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

Humanoid:MoveTo - Walks instead of Teleports?

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.

3 answers

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

If you wan't him/her to teleport to a location, you use X, Y, Z coordinations.

1 comment

0

I want the player to teleport to the .hit which is why I am asking the question.

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