Delay Teleport From Part To Part?

Hi all, I’m currently trying to make a part to part teleport script. Here it is:


local point = game.Workspace.MiraculousTP2
local db = true
local cooldown = 2

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local character = plr.Character.HumanoidRootPart
	if db == true then
		db = false
		character.CFrame = CFrame.new(point.Position)
		script.Disabled = true
		wait(cooldown)
		script.Disabled = false
		wait(.2)
		db = true
	end
end)

When I try and teleport from part to part, I can never get out of the teleport sequence so I just keep teleporting back and forth, back and forth - its impossible to jump out of the teleport pad sequence (if that makes sense?) so I just keep going back and forth.
How can I fix this? Thanks.

1 Like

Add a longer debounce, about 1 second.

Also, you should check if the touching part is a humanoid before making them teleport, otherwise your script may error.

You could also set up a BindableEvent or such that checks if the player is teleporting from the other pad, and if they are then don’t teleport them.

1 Like
local point = game.Workspace.MiraculousTP2
local db = true

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	local character = plr.Character.HumanoidRootPart
	if db == true then
		wait(2)
		db = false
		wait(2)
		character.CFrame = CFrame.new(point.Position)
		wait(2)
		db = true
	end
end)

Added a longer debounce, but this time I can step off the teleport part but then like 1 second later I get teleported anyways.

1 Like

Just had an idea. Set up a value (any type), and put it on the player when teleporting. If the player has that value, don’t teleport them. Then destroy the value.

2 Likes