Hey guys, I have a teleporter which is supposed to teleport you to the other one. I dont script so I dont know what I have done wrong. Please help.
3 Likes
These might help you:
1 Like
Thanks!
What would be the full script to teleport a player instantly from “Teleporter A” to “Teleporter B” when walked into?
local partA = workspace.TeleporterA --Set this to your part
local partB = workspace.TeleporterB --Set this to your part
local teleportedPlayers = {}
--Whenever teleporterA is touched
partA.Touched:Connect(function(hit)
--If the touched part is a player
if hit and hit.Parent and hit.Parent:FindFirstChildWhichIsA("Humanoid") then
--if the player hasn't touched this part before
if not teleportedPlayers[hit.Name] then
table.insert(teleportedPlayers, #teleportedPlayers + 1, hit.Name)
hit.Parent:SetPrimaryPartCFrame(partB.CFrame)
end
end
end)
--Whenever a player touches teleporterB
partB.Touched:Connect(function(hit)
--If the touched part is a player
if hit and hit.Parent and hit.Parent:FindFirstChildWhichIsA("Humanoid") then
--if the player hasn't touched this part before
if not teleportedPlayers[hit.Name] then
table.insert(teleportedPlayers, #teleportedPlayers + 1, hit.Name)
hit.Parent:SetPrimaryPartCFrame(partA.CFrame)
end
end
end)
--When the player walks away from the part remove their name from the table
function onTouchEnded(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if teleportedPlayers[hit.Name] then
table.remove(teleportedPlayers, table.find(teleportedPlayers, hit.Name))
end
end
end
partA.TouchEnded:Connect(onTouchEnded)
partB.TouchEnded:Connect(onTouchEnded)
So basically right in models we have this thing called the root part, or primary part in other words. If they are rigged together we can set its cframe to be anothers cframe to update everything. Think of cframe as implicit and position as explicit. Anyways we would simply set the primary part of our model (character) to the new cframe we want (CFrame.new() takes a vector3)
Here is a full simple teleportation script from a point to another that I made it’s uncopylocked feel free to use it!
Edit: I made it so that it teleports you to another portal.