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

How to stop a button from being clicked more then once?

Ok,I made script so when you press a button it fades and then in the last part I added a debounce so it can only be clicked once, but your still able to click it,why?

part = script.Parent
clicked = false
part.MouseButton1Click:connect(function()
---------------Debounce------------------
 if clicked == false--Checks if clicked is false(Which it should be,because it already been set false)
	then 
	clicked = true-- Since it false it will turn it true(so we know it's alread been clicked)
end

----------------Fade Out------------------
	for fo = 0,10 do
		wait(0.1)
		part.BackgroundTransparency = fo/10--You need to divide to get the precise number(Other way won't work)
		part.TextTransparency = fo/10
		if fo/10 ==1
			then
			clicked = false
		
		end	
	end
	
end)

1 answer

✓ Accepted answer

You need the debounce with the script

part = script.Parent
clicked = false
part.MouseButton1Click:connect(function()
----------------Fade Out------------------
if clicked == true then
	clicked = false
	for fo = 0,10 do
        wait(0.1)
        part.BackgroundTransparency = fo/10--You need to divide to get the precise number(Other way won't work)
	part.TextTransparency = fo/10
		if fo/10 ==1 then
			clicked = false
		end
	end
	end
end)

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