I'm trying to make it so when a player clicks a button the button waits for 3 seconds before it can work again but every time I tried to do it if the player spam clicks it the function still gets spammed, is there any way to add a cooldown to when the button can be pressed?
Discord: Unknown Intelligence#6569
local bool = true
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local light = game:GetService("Lighting")
light.TimeOfDay = 1
light.FogEnd = 50
light.FogStart = 20
light.Brightness = 0
light.FogColor = Color3.new(0,0,0)
end)
function onMouseClick()
if bool == true then
local light = game:GetService("Lighting")
script.Lightson:Play()
light.TimeOfDay = 12
light.FogEnd = 1000000
light.FogStart = 0
bool = false
else if bool == false then
local light = game:GetService("Lighting")
script.Lightsoff:Play()
light.TimeOfDay = 1
light.Brightness = 0
light.FogColor = Color3.new(0,0,0)
light.FogEnd = 50
light.FogStart = 25
bool = true
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onMouseClick)

2 comments
Did you try "wait(3)"?
Yeah that's what I did and it just waited 3 seconds before bombarding you with the spams xD