Okay, snaz, you’ve got it working, but I would like to introduce you to a fundamental principal that makes us stop repeating ourselves while we code, this is useful as it:
-
Saves us time when writing code
-
Makes it easier for other programmers to read.
We should also make sure that our code is as efficient as possible, this means we shouldn’t have any lines of code we don’t need.
This is my attempt at tidying up your code, I have added a list of comments below, just to let you know what I’ve changed:
local TweenService =game:GetService("TweenService")
local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator")
local gui = script.Parent
local Debounce = false
TouchPart.Touched:Connect(function(hit)
if hit.Parent.Name == game.Players.LocalPlayer.Name and Debounce == false then
TweenService:Create(gui.TextLabel, TweenInfo.new(1), { TextTransparency = 0 }):Play()
print("Gui opened")
Debounce = true
end
end)
What I changed:
-
Import the TweenService, this allows us to interpolate properties of instances (this allows to create easy animations).
-
I add something called a debounce, in short roblox will continuously fired the Touched event, even if the user is touching the part and not moving, which is not good as it will make the code execute too many times.
- To counter this we add a Debounce variable, meaning as soon as we touch it, we set this variables value to True and this prevents the code which makes the TextLabel Text visible can’t run again.
-
I also removed the TextTransparency=1 line here as it is useless, just text TextTransparency to be inside of Roblox Studio.
-
Before you were checking two times, if their was a player & if the player had a specific name, I made this one check, I also check to make sure the value of the Debounce variable is false.
-
I then create a Tween, which I set to take 1 second, you can change the amount of seconds by ammending that line.
-
I then play the tween I’ve created.
-
I print “Gui Opened”, as you had that before.
-
Then I set debounce to be true so that the code can’t run again.
Hope this helps!