Hello!
So I’ve made a tweening gui frame whenever someone clicks its button, it fires.
however, if i spam the button, it will glitch the frame and ruin the entire script.
Hey, I would suggest using debounce, this is a cooldown between every tween and prevents it from glitching. So I would do something like this:
local frame = script.Parent.Parent.CreditsFrame
local button = script.Parent
local debounce = true -- The debounce is true
local exit = frame.Exit
button.MouseButton1Click:Connect(function()
if frame.Visible == false and debounce == true then -- If the debounce is true then
-- button = nil {I disabled this because you don't need to have this here}
debounce = false -- The script runs and debounce = true
frame.Visible = true
frame:TweenSize(UDim2.new(0, 387,0, 50), "InOut", "Quint", .3) -- I reccomend saying this instead of nil
wait(.3)
frame:TweenSize(UDim2.new(0, 387,0, 247),"InOut", "Quint", .3)
wait(1) -- Wait one second (the cooldown) before the debounce is true again
debounce = true -- Setting the debounce to true
end
end)
I also cleaned up your code a bit, if you’ve any questions ask me!
local frame = script.Parent.Parent.CreditsFrame
local button = script.Parent
local exit = frame.Exit
local debounce = true
button.MouseButton1Click:Connect(function()
if frame.Visible == false and debounce == true then
debounce = false
frame.Visible = true
frame:TweenSize(UDim2.new(0, 387,0, 50),"InOut", "Quint", .2)
wait(.3)
frame:TweenSize(UDim2.new(0, 387,0, 247),"InOut", "Quint", .2)
wait(.6)
local credits = {frame.Credits,
frame.Credits2,
frame.Credits3,
frame.Exit
}
for _,credits in ipairs(credits) do
credits.Visible = true
for i = 1, 0, - .1 do
credits.TextTransparency = i
wait()
end
exit.MouseButton1Click:Connect(function()
credits.Visible = false
debounce = true
end)
-- Whole Script
end
end
end)
First of all, I saw you didn’t revert any of the actions the script made at making it transparent, you also placed the debounce wrong, I’m now working on it and I’ll send you the solution when it’s done.
Okay, so, I first of all cleaned the code up, made the ends more organizized, placed the debounce good and made the debounce 2 seconds instead of one. This should work:
local frame = script.Parent.Parent.CreditsFrame
local button = script.Parent
local exit = frame.Exit
local debounce = true
button.MouseButton1Click:Connect(function()
if frame.Visible == false and debounce == true then
debounce = false
frame.Visible = true
frame:TweenSize(UDim2.new(0, 387,0, 50),"InOut", "Quint", .2)
wait(.3)
frame:TweenSize(UDim2.new(0, 387,0, 247),"InOut", "Quint", .2)
wait(.6)
local credits = {
frame.Credits,
frame.Credits2,
frame.Credits3,
frame.Exit
}
for _, credit in ipairs(credits) do
credit.Visible = true
for i = 1, 0, - .1 do
credit.Transparency = i
wait()
end
exit.MouseButton1Click:Connect(function()
credit.Visible = false
credit.Transparency = 1
end)
end
wait(2)
debounce = true
end
end)