I have this ClickDetector event, that connects to a function, that moves a part. However, when I press the button multiple times, the animation starts all over again. How would I make the ClickDetector work only once?
ClickDetector1.MouseClick:Connect(function()
local Arrow2X = Arrow2.CFrame.X
local OldArrow2X = Arrow2.CFrame.X
local Arrow2TorsoY = Arrow2.CFrame.Y
local Arrow2TorsoZ = Arrow2.CFrame.Z
local Arrow2Ori = Arrow2.Orientation
wait(4.25)
if 2+2==4 then
for i = 1,145,1 do
Arrow2X = Arrow2X + 0.59
Arrow2.CFrame = CFrame.new(Arrow2X,Arrow2TorsoY,Arrow2TorsoZ)
Arrow2.Orientation = Arrow2Ori
wait(0.005)
end
for i = 1,10 do
Arrow2.Transparency = Arrow2.Transparency + 0.1
wait(0.1)
end
end
end)

2 comments
What if I need to click the button to make a GUI object show up and click again to close the GUI, while playing the animation?
You would use a bool variable and if statement to determine if the gui was open or closed.