Need help on adding a cooldown to my light script

So basically when I click the button the light.Enabled = false and when I click the button again the light.Enabled = false. I am trying to figure out how to add a cooldown to the script so players won’t be able to spam the button.

Here is the script:

local button = game.Workspace.LampModel.Button.ClickDetector
local light = game.Workspace.LampModel.Lamp.PointLight
DEBOUNCE = false

button.MouseClick:Connect(function()
	
	if light.Enabled == false and not DEBOUNCE then
		light.Enabled = true
	else 
		light.Enabled = false
	end
	
end)

1 Like
local button = game.Workspace.LampModel.Button.ClickDetector
local light = game.Workspace.LampModel.Lamp.PointLight
DEBOUNCE = false
amount = 2
button.MouseClick:Connect(function()
	
	if not DEBOUNCE then
		DEBOUNCE = true
		light.Enabled = not light.Enabled
		task.wait(amount)
		DEBOUNCE = false
	end
end)

something basic like dis

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.