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

Small problem with my GUI?

Asked by
Relatch 550 Moderation Voter
10 years ago

For my gui if I spam click the button, the frame glitches. How would I stop it from glitching when it's spam clicked?

Script:

Time = 1

script.Parent.MouseButton1Click:connect(function()
    if script.Parent.Text == "SHOP" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", Time)
        wait(0.1)
        script.Parent.Text = "CLOSE"
    elseif script.Parent.Text == "CLOSE" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 1, 0), "Out", "Quad", Time)
        wait(0.1)
        script.Parent.Text = "SHOP"
    end
end)

1 answer

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

Do you want the frame to get like overridden (Say it's half way out and you want it to come back in at that moment), or do you want to have it wait until the frame is completely out? Either way, there is a answer to both of these.


Override;

Time = 1

script.Parent.MouseButton1Click:connect(function()
    if script.Parent.Text == "SHOP" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", Time, true)
        wait(0.1)
        script.Parent.Text = "CLOSE"
    elseif script.Parent.Text == "CLOSE" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 1, 0), "Out", "Quad", Time, true)
        wait(0.1)
        script.Parent.Text = "SHOP"
    end
end)

There is an argument for overriding a Guis destination, all you had to do was add , true inside the methods. This argument will allow you to send a Gui out one way, and if you change your mind, send it back.


Wait until it reaches its destination.

Time = 1

script.Parent.MouseButton1Click:connect(function()
    if script.Parent.Text == "SHOP" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", Time)
        repeat wait() until script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", Time)
        script.Parent.Text = "CLOSE"
    elseif script.Parent.Text == "CLOSE" then
        wait(1/30)
        script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 1, 0), "Out", "Quad", Time)
        repeat wait() until script.Parent.Parent.MainFrame:TweenPosition(UDim2.new(0, 0, 1, 0), "Out", "Quad", Time)
        script.Parent.Text = "SHOP"
    end
end)

Now, the Tween methods return a bool telling if the method is done or not, all you have to do is add a loop wait until the method is finished.

0
If I keep spam clicking it, after it goes up and down, it goes up and down again. Relatch 550 — 10y
Ad

Answer this question