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

Add Cooldown To Teleport To Location Part ?

Hello I Need your help,can someone add a cooldown to this script,like wait (5) thingy,(i tried to add wait(5) but it doesnt work

Heres the script:

function onTouch(part) local Toucher = part.Parent:FindFirstChild("Humanoid")

if Toucher ~= nil then

Toucher.Torso.CFrame = CFrame.new(-11.97, 0.5, 53.22)--where you place the cordinants and to do that
--you have to place a part then open properties slect the part look at position then put the code in 
--there

end

end

brick = script.Parent brick.Touched:connect(onTouch)

please edit it and just add a cooldown

2 answers

Adding a wait won't do anything without a debounce. Every time the Touched event is fired, the wait will be ignored. A debounce will prevent the code from running even if the event connects.

local debounce = true
script.Parent.Touched:Connect(function(hit)
	-- Is hit and touchable
	if hit and hit.Parent and debounce then
		-- Is Player?
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then 
			-- Is Humanoid
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			-- Is player alive
			if Humanoid and Humanoid.Health > 0 then
				-- set debounce to prevent spam
				debounce = false
				Player.Character:SetPrimaryPartCFrame ( CFrame.new(-11.97, 0.5, 53.22) )
			end
		end
		wait(3)
		-- reset debounce
		debounce = true
	end
end)

just add a wait()

if Toucher ~= nil then
Toucher.Torso.CFrame = CFrame.new(-11.97, 0.5, 53.22)

wait()  ---- how long you want to  cool down
 
end

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