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

Why doesn't my NPC which is supposed to walk to the player goes to the wall instead?

So basically I have script located inside an NPC's head which is supposed to make him walk to the player (1 player server btw). However, he instead goes straight for the wall. Could somebody help me fix this problem please?

Script:

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
while true do
wait(.1)
script.Parent.Parent.Humanoid.WalkToPoint = Vector3.new(char.HumanoidRootPart.Position)
end
end)
end)

1 answer

✓ Accepted answer

Using WalkToPoint makes the Humanoid move from its current Vector3 position to the Vector3 position provided by WalkToPoint. This causes the Humanoid to run in a straight line, regardless of what is in its way.

There is pathfinding in Roblox, however it requires more scripting. https://developer.roblox.com/articles/Pathfinding Here is a link that will hopefully teach you more about it. I feel that it is explained well enough for me to not go into detail. Best of luck!

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