Tool = script.Parent function onTouched(hit) if hit.ClassName == "Part" then local Humanoid = script.Parent.Parent.Parent.Parent:WaitForChild("Humanoid") if Humanoid then Humanoid:MoveTo(hit.Position) end return; end end Tool.Touched:connect(onTouched)
The script above works perfectly fine, although, at the part:
Humanoid:MoveTo(hit.Position)
I'm not getting any errors, it's just the player moves towards that location rather than teleporting to that position, not sure why it does this. Any help would be useful.
Humanoid:MoveTo
makes humanoids walk. Model:MoveTo
teleports a model. You want to teleport the character instead of telling its humanoid to walk. Write Humanoid.Parent:MoveTo(hit.Position)
to teleport the character model.
1Waffle1's answer is good, but if you're looking for an alternative, change the player's torso's CFrame:
mouse.Button1Down:connect(function() char.Torso.CFrame = mouse.Hit.p + Vector3.new(0,7,0) -- so the player doesn't teleport into the ground/wall/whatever end