Instead of teleporting to a specific location, you just teleport to a brick named, for example, 11?
function onTouched(hit) - What to put in! end script.Parent.Touched:connect(onTouched)
If you could redirect me to a page that could explain this, i would be way happier than just getting the answer.
Help?
This is what I assume you have so far.
TeleportPart = workspace["11"] function onTouched(hit) end script.Parent.Touched:connect(onTouched)
What you want to do is find out if the part touching this teleporter is part of a player (and is ideally alive). Use:
:GetPlayerFromCharacter() - Returns a player instance from a character object, or nil if it doesn't exist.
:FindFirstChild() - Returns the child from a string, or nil if it doesn't exist.
TeleportPart = workspace["11"] function onTouched(hit) local HumanoidIsFound = hit.Parent:FindFirstChild("Humanoid") local PlayerIsFound = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then local Character = hit.Parent end end script.Parent.Touched:connect(onTouched)
Now teleport the character! Use either:
:MoveTo() - Moves the PrimaryPart of a model to the given Vector3 position.
:SetPrimaryPartCFrame() - Moves the PrimaryPart of a model to the given CFrame position.
TeleportPart = workspace["11"] function onTouched(hit) local HumanoidIsFound = hit.Parent:FindFirstChild("Humanoid") local PlayerIsFound = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent and HumanoidIsFound and HumanoidIsFound.Health > 0 and PlayerIsFound then local Character = hit.Parent Character:MoveTo(TeleportPart.Position) --[[ Or Character:SetPrimaryPartCFrame(TeleportPart.CFrame) --]] end end script.Parent.Touched:connect(onTouched)
And then you're done!
a = script.Parent --What you step on b = workspace.B --What you teleport to a.Touched:connect( --When point A touched function(part) --Do the following: local player = game.Players:GetPlayerFromCharacter(part.Parent) --The player that's controlling the character model that contains the part that touched A if player then --If player exists local torso = player.Character.Torso --The guy's torso torso.CFrame = b.CFrame * CFrame.new(0, 4, 0) --See note attached end end )
So, we have the position of point B. We want to put the character's torso a little bit above the part so he doesn't get stuck in the ground. To do this, we first take the position of the exit node.
b.CFrame
Now, we have to get a point 4 studs above that. To do this, we use * to make a new position related to the position of the exit node.
b.CFrame * CFrame.new(0, 4, 0)
This takes the original CFrame of b, then makes a CFrame 4 units above that point. Got it?