Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this simple teleportation script not working?

Asked by
TNTeon -1
6 years ago

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?

2 answers

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago

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)


Ad
Log in to vote
0
Answered by
RjsMc 48
6 years ago

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
  1. Lets add the teleport function.
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.

0
Sorry. Error fix. The last end is end). RjsMc 48 — 6y

Answer this question