Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why this debounce is not working?

local credits = false
local SG = script.Parent.Parent.Parent
local debounce = false

script.Parent.MouseButton1Click:connect(function ()
	if credits == false and debounce == false then
		credits = true
		debounce = true
	end	
	if credits == true and debounce == false then
		credits = false
		debounce = true
	end
	if credits == true and debounce == true then
		SG.Credits.Visible = true
		for i = 1, 14 do
			SG.Credits.Position = SG.Credits.Position + UDim2.new(0.05,0,0,0)
			wait(0)
			if i == 14 then
				script.Parent.Text = "Close Credits"
				debounce = false
			end
		end
	end	
	if credits == false and debounce == true then
		for i = 1, 14 do
			SG.Credits.Position = SG.Credits.Position - UDim2.new(0.05,0,0,0)
			wait(0)
			if i == 14 then
				script.Parent.Text = "Credits"
				SG.Credits.Visible = false
				debounce = false
			end
		end
	end
end)

So, the debounce here is to avoid that people that clicks a milion a times per second to open something and bugs the gui, right? Well im using debounce, but when i click alot of times on the button, the gui bugs. Whats the problem?

2 comments

0

You're setting credits to true and then asking if credits is true. the end if at line 9 looks like it should be elseif.

0

Waffle, it is supposed to be like that, credits is the gui. If credits is true, when you click, is false, that will make the gui invisible, and if credits is false and when i click credits is true, the credits gui will be visible, and i already tried to put an elseif

1 answer

Your script isn't wrong, it's running exactly how you told it to run.

This discussion is preserved as it was. New answers, comments, and votes are closed.