how do i make a part teleport you to a next part? like when you step on it it teleports you to another part
COMMUNITY QUESTION
how to teleport players?
2 answers
We can use the BasePart.Touched event to make a part teleport a player to a location when it is touched.
This would be a script in game.ServerScriptService:
local Teleporter = worksapce.Teleporter
local TargetPosition = Vector3.new(1, 1, 1)
Teleporter.Touched:Connect(function(TouchedPart)
if not TouchedPart.Parent then
return
end
local Player = game.Players:GetPlayerFromCharacter(TouchedPart.Parent)
if not Player then
return
end
local Character = TouchedPart.Parent
Character:MoveTo(TargetPosition)
end)
In practice, you'd want to check if the character was recently teleported as a form of debouncing, as the BasePart.Touched event will likely fire a number of times from different character parts.
local Enabled = true
local Cooldown = 1.5 -- change the cooldown if you want
local Part1 = workspace.Part1 -- locate your first part
local Part2 = workspace.Part2 -- locate your second part
function TELEPORT(torso, position)
Enabled = false
torso.CFrame = CFrame.new(position)
wait(Cooldown)
Enabled = true
end
Part1.Touched:connect(function(hit)
if Enabled then
if hit and hit.Parent:FindFirstChild('Torso') then
TELEPORT(hit.Parent:FindFirstChild('Torso'), Part2.CFrame)
end
end
end
Part2.Touched:connect(function(hit)
if Enabled then
if hit and hit.Parent:FindFirstChild('Torso') then
TELEPORT(hit.Parent:FindFirstChild('Torso'), Part1.CFrame)
end
end
end)
2 comments
0
If you step on Part1, teleports to Part2. Step on Part2, teleports to Part1.
0
You can remove the Part2.Touched function if you don't want the player to be able to teleport back.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I tried the script and it works but i keeps teleporting me above the teleporter itself