Hello! So now I'm trying to make some scripted NPCs. So I have seen the way that some Zombie models work and how they walk to a humanoid. The script is very complicated though. So I decided to make my own simpler version! I actually made the base of this script using another model I made but Modified it. So basically when the player enters the NPC is supposed to walk to the player's position (Torso)
It doesn't work however. When I put the position of the torso, the NPC just walks to 0,0,0. But if I take the Position out and put it to a specific vector3. it walks to it. So I know it's working but I don't know why it won't walk tot he player. Any help?
game.Players.PlayerAdded:connect(function(p)--When a Player joins this function is triggered! p.CharacterAdded:connect(function(c)-- when a character is added (A physical robloxian) this function will be triggered! this also happens when you respawn! spawn(function()--When a character is spawned this function is triggered! while wait() do--This is an infinite loop! script.Parent.Humanoid.WalkToPoint = Vector3.new(c.Torso.Position) --Won't walk to this end end) end) end)
Why create a new vector, when the Torso's position is a vector property itself?
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) spawn(function() while wait() do script.Parent.Humanoid.WalkToPoint = c.Torso.Position -- This is changed. end end) end) end)
The reason is because you are saying Vector3.new(c.Torso.Position), That's like saying:
Vector3.new(Vector3.new(0,3.5,0))
You should use :MoveTo
on the Humanoid instead of walk to point. NOTE If you use this on other objects like parts or models, It will teleport them.
Humanoid:MoveTo(Vector3.new(50,0,40)) --Walk to 50,0,40
This is the same thing as Redbullusa's Script except I used :MoveTo()
.
game.Players.PlayerAdded:connect(function(p)--When a Player joins this function is triggered! p.CharacterAdded:connect(function(c)-- when a character is added (A physical robloxian) this function will be triggered! this also happens when you respawn! spawn(function()--When a character is spawned this function is triggered! while wait() do--This is an infinite loop! script.Parent.Humanoid:MoveTo(Vector3.new(c.Torso.Position)) end end) end) end)
Hope it helps!
Try Humanoid.WalkToPart(c.Torso) as your no longer using a point, also, I think a problem may be that the torso is constantly moving, in that case you may want to use the standard method in zombie follow scripts which is below
--Try this on line 5 of your script posted above Humanoid.WalkToPart(c.Torso) script.Parent.Humanoid:MoveTo(c.Torso.Position, c.Torso)