I need help with this script

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.

Here’s a GIF (The second one is when i spam the button)
https://i.gyazo.com/4887670bf958a7ab01e88ad9f13efbbc.mp4

support is appreciated!

Script:

local frame = script.Parent.Parent.CreditsFrame
local button = script.Parent
local exit = frame.Exit

button.MouseButton1Click:Connect(function()
if frame.Visible == false then
button = nil
frame.Visible = true
frame:TweenSize(UDim2.new(0, 387,0, 50),nil, nil, .3)
wait(.3)
frame:TweenSize(UDim2.new(0, 387,0, 247),nil, nil, .3)
end)
end)
1 Like

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! :slightly_smiling_face:

1 Like

Thank you so much! but i have a problem, i tried an autoclicker, it glitched it only that way, is it fine?

I don’t think someone will do it with a autoclicker, so guess that’s fine.

1 Like

uh oh… I’ve encountered a problem…
When I click too fast it glitches but in a different way…

GIF: https://i.gyazo.com/c4baa09c9f13e01cf5711088d8971b3b.mp4

script:

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)
1 Like

Hmm… I can’t just type this like that and I want to test it now, could you send the file too so I can test it myself?

here’s the file tweenguicredit.rbxl (25.1 KB)

1 Like

Why use a denounce when you can disable the button and then reenable it

how would i do that? i don’t understand much of scripting

Yes, but it doesn’t really matter what you use.

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.

1 Like

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)
2 Likes

Thanks! how do you have those spaces between scripts
mine is like

if frame.Visible == false and debounce == true then
debounce = false

and not

	if frame.Visible == false and debounce == true then
		
		debounce = false

its confusing

What do you mean exactly? (30 Characters)

Like, when i press enter after an if statement etc.
it does these spaces between the sentence.

welp its still buggy… If i click instantly after i close it it will just bug out, weird…