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

How to add a cooldown to my hat giver script?

Asked by 3 years ago

I have a hat giver script but i need a cooldown for it but i don't know how. Here is the script:

script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then local hat = game.ServerStorage.Hat:Clone() hat.Parent = hit.Parent end end)

2 answers

Log in to vote
0
Answered by
Punctist 120
3 years ago

Try this

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if debounce == false then
    debounce = true
            local hum = hit.Parent:FindFirstChild("Humanoid")
            if hum then
            local hat = game.ServerStorage.Hat:Clone()
            hat.Parent = hit.Parent
            end
    wait(3)
    debounce = false
    end
end)


0
Thx Punctist it work! O0O0O0oOOO0OOO -10 — 3y
0
No problem! Punctist 120 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You just have to put in wait() like this:

script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then wait(3) local hat = game.ServerStorage.Hat:Clone() hat.Parent = hit.Parent end end)
0
YoungsterJeremy1 it not work it put too much hats on my character O0O0O0oOOO0OOO -10 — 3y
0
I does work I did this script and it put one hat on mine so maybe something is wrong? YoungsterJeremy1 6 — 3y

Answer this question