I Don't understand why this simple teleportation script is not working. Here is the script.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then hit.Parent.Head.CFrame = CFrame.new(72.076, 15.156, -57.762) end end)
Can someone please help?
Instead of hit.Parent.Head
, use hit.Parent.HumanoidRootPart
or hit.Parent.Torso
.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then hit.Parent.Torso.CFrame = CFrame.new(72.076, 15.156, -57.762) end end)
If the thing is supposed to teleport you, I am sending you a code that works for both R6 and R15. Teleporting the Humanoid wont work in some cases.
To start we get the part name that hits the part. Thats easy.
script.Parent.Touched:connect(function(part) end
In this code above, it will detect the part that touches the teleportation part.
Now we make it inside where it detects the Humanoid. If you dont do this, it will teleport any part that touches it, instead of the player. You already did this, but I will type it out anyway.
local humanoid = part.Parent:FindFirstChild("Humanoid")
Now we add an if statement for if the humanoid is detected. This then prevents any other part to teleport. This part is easy.
if humanoid then end
In here, if humanoid exists, if you add a print(humanoid)
it will say Humanoid, saying it exists!
Now the actual part. Making the player teleport. In this case we are teleporting the Humanoid root part. This is because the Humanoid root part is the most reliable. This works with both R6 and R15.
-- Adding codes from above... script.Parent.Touched:connect(function(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid then -- Teleporting function end end
script.Parent.Touched:connect(function(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid then -- Teleporting function part.Parent.HumanoidRootPart.CFrame = CFrame.new(72.076, 15.156, -57.762) end end ~~~~~
And thats it. It seems like you know everything else so I dont have to explain CFrame and using of if statements. Please look at the Roblox Wiki for more information. Please mark as correct if this helped you.