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

Debounce not working correctly (Un local script) ?

local buttonPressed = false
function onClicked(playerWhoClicked)
 if not buttonPressed then
	
	 if buttonPressed == false then
		buttonPressed = true
	 

    local car = game.ServerStorage.Car:Clone()

    car .Parent = workspace
    car:MakeJoints()
buttonPressed = false

end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
end

I have tried looking on other videos but they dont seem to work. HELP !

1 answer

✓ Accepted answer

#What's the problem You're changing the debounce back to false too quickly! Add a cool down timer.


#Final Product

local buttonPressed = false
local cooldown_time = 5 --the amount of time in seconds that you need to wait before next use.

function onClicked(playerWhoClicked)
	if not buttonPressed then
		buttonPressed = true
		local car = game.ServerStorage.Car:Clone()
		car .Parent = workspace
		car:MakeJoints()
		wait(cooldown_time)
		buttonPressed = false
	end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)


Hope it helps!

1 comment

0

Sorry, there was an error earlier in the code. I revised it and it should be working like normal now.

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