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

getting player to walk to a spot?

I used this script to get a player to walk to a part, but it just teleports the player to the part instead. What do I need to add the script to get the player to walk to the part instead of teleporting to it.

workspace.Test.Touched:connect(function(hit) local pos = game.Workspace.Part.Position game.Players.LocalPlayer.Character:MoveTo(pos)

end)

1 answer

✓ Accepted answer

The function :MoveTo has two different uses in Roblox Lua.

The method that you used is a function of Model Objects - this teleports the model to that position instantly.

The method that you need to use is a function of a Humanoid - this will walk the humanoid to the desired position.

To do this, we just need to alter your code slightly.

game.Workspace.Test.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local pos = game.Workspace.Part.Position
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		humanoid:MoveTo(pos)
	end	
end)

Note that you do not have to use the part's Position when walking a humanoid using :MoveTo, as it can just walk to a a part.

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