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

Is there any way to add a cool down to this script?

So I'm making a simulator in Roblox, and I'm trying to add a cool down to a gun, and I don't know how.

script.Parent.Lift.OnServerEvent:Connect(function()
	local energy = game.Players[script.Parent.Parent.Name].leaderstats.Energy
	energy.Value = energy.value + 1
end)

1 answer

Hello!

You can add a cooldown by adding a debounce.

local debounce = false
local CooldownTime = 1

script.Parent.Lift.OnServerEvent:Connect(function()
	if not debounce then
	    debounce = true
	    local energy = game.Players[script.Parent.Parent.Name].leaderstats.Energy
	    energy.Value = energy.value + 1

	    wait(CooldownTime)

            debounce = false	   
	end
end)

I made this on the editor on this site if it's messy my bad.

1 comment

0

Thanks!!!

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