Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I stop this event from firing multiple times?

Asked by 5 years ago

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)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Use the MaxActivationDistance property of the ClickDetector and set it to 0, doing this will make it impossible to click the detector and activate the function. Then, after however long the animation takes you can set it back to the default value.

ClickDetector1.MouseClick:Connect(function()
    ClickDetector1.MaxActivationDistance = 0
    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)
0
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? AndriusTheGreat 140 — 5y
0
You would use a bool variable and if statement to determine if the gui was open or closed. FallenZalio 99 — 5y
Ad

Answer this question