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

How Do I Add An Cooldown On This Script??

Hello, I'm A Beginner In Scripting And I'm Making A Simulator Game And I'm Making A Script And I Don't Know How To Add A Cooldown In Here So Could Anyone Do It?

local Players = game:GetService("Players")
local sword = game.ReplicatedFirst.ClassicSword

local part = script.Parent
local function onTouched(part)  
    local player = Players:GetPlayerFromCharacter(part.Parent)
    if not player then return end
    local backpack = player.Backpack
    sword:Clone().Parent = backpack
end
part.Touched:Connect(onTouched)

Disclaimer : This Is A Repost

1 comment

0

use debounce

1 answer

✓ Accepted answer

add a debounce:

local Players = game:GetService("Players")
local sword = game.ReplicatedFirst.ClassicSword
local debounce = false

local part = script.Parent
local function onTouched(part)  
    if not debounce then
		debounce = true
		local player = Players:GetPlayerFromCharacter(part.Parent)
		if not player then return end
		local backpack = player.Backpack
		sword:Clone().Parent = backpack
		delay(5, function()
			debounce = false
		end)
	end
end
part.Touched:Connect(onTouched)

pls accept this answer if this fixed ur problem

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