✓ Accepted answer
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)
end
end
script.Parent.Touched:connect(onTouched)
And then you're done!
1 comment
Add a code block so we can read it... just press the little lua button and put the script in betweem the two ~~~ lines. To change your question just press edit on the side, dont repost this!