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

How to add a cooldown to my hat giver script?

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

✓ Accepted answer

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)


2 comments

0

Thx Punctist it work!

0

No problem!

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)

2 comments

0

YoungsterJeremy1 it not work it put too much hats on my character

0

I does work I did this script and it put one hat on mine so maybe something is wrong?

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