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

getting player to walk to a spot?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question