Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleport to part, not position.

Could anyone tell me where I went wrong?

function onTouched(part)
 local h = part.Parent:findFirstChild("Torso")
 if (h ~=nil) then
h.CFrame = script.Parent.Parent.Parent.Part1.Position.CFrame

 end
 end

script.Parent.Touched:connect(onTouched)

3 answers

✓ Accepted answer

Thetacah you were close, however you have to use CFrame.new, and you tried to CFrame the humanoid instance:

function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
t = h.Parent.Torso
t.CFrame = CFrame.new(script.Parent.Parent.Parent.Part1.Position)
end
end
--Keep in mind that the player will go inside of that part, but if you want to get the player on top of it you can PM my ROBLOX

script.Parent.Touched:connect(onTouched)

Where you went wrong was you put Position.CFrame, where the only sub-properties of Position are X, Y, and Z.

1 comment

0

I raised the part over the ground so that the player is not stuck in the ground. Thank you.

I don't use CFrame to often, but I think this should work.


function onTouched(part)
 local h = part.Parent:findFirstChild("Humanoid")
 if h ~=nil then
h.CFrame = script.Parent.Parent.Parent.Part1.Position

 end
 end

script.Parent.Touched:connect(onTouched)

If you want to move the player to the part do this.


function onTouched(part)
 local h = part.Parent:findFirstChild("Torso")
 if (h ~=nil) then
h.CFrame =CFrame.new(script.Parent.Parent.Parent.Part1.CFrame.x,script.Parent.Parent.Parent.Part1.Position.y+3,script.Parent.Parent.Parent.Part1.Position.z)

 end
 end

script.Parent.Touched:connect(onTouched)

This discussion is preserved as it was. New answers, comments, and votes are closed.