Cooldown on a refresher script

i have this script which refreshes the player at the current location but it keeps teleporting the player in an infinite loop so all i need is a cooldown

local Players = game:GetService("Players")
local TPDest = workspace.Washer

script.Parent.Touched:Connect(function(partTouched)
	if partTouched.Parent:FindFirstChild("Humanoid") then
		local Character = partTouched.Parent
		local Player = Players:GetPlayerFromCharacter(Character)
        Player:LoadCharacter()
        Player.Character:WaitForChild("HumanoidRootPart").CFrame = TPDest.CFrame
        if Player.Character:FindFirstChild("ForceField") then Player.Character:FindFirstChild("ForceField"):Destroy() end
	end
end)
local Players = game:GetService("Players")
local TPDest = workspace.Washer
local cooldown = false
local cooldowntimer = 5 -- Change this to whatever you want the cooldown to be

script.Parent.Touched:Connect(function(partTouched)
	if partTouched.Parent:FindFirstChild("Humanoid") and not cooldown then
        cooldown = true
		local Character = partTouched.Parent
		local Player = Players:GetPlayerFromCharacter(Character)
        Player:LoadCharacter()
        Player.Character:WaitForChild("HumanoidRootPart").CFrame = TPDest.CFrame
        if Player.Character:FindFirstChild("ForceField") then Player.Character:FindFirstChild("ForceField"):Destroy() end
        wait(cooldowntimer)
        cooldown = false
	end
end)

Try that script, I added a cooldown for you, you can simply just change the cooldowntimer to whatever you want the cooldown time to be and it will work just fine.

2 Likes