Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
4 years ago

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.

0
Thanks!!! greasychickenugget 0 — 4y
Ad

Answer this question