I made a script that should make the NPC follow anything with a humanoid in it (because my game has models that need to be followed as well) but when I run the script, the NPC’s humanoid WalkToPoint turns to 0,0,0 which I don’t know why and makes the NPC walk off the map.
Images
Source code:
local players = game:GetService('Players')
local zombie = script.Parent
local humanoid = zombie:FindFirstChildOfClass('Humanoid')
function walk()
while wait() do
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA('Humanoid') and v.Parent:FindFirstChild('HumanoidRootPart') then
local c = v.Parent
local hrp = c.HumanoidRootPart
humanoid.WalkToPoint = Vector3.new(hrp.Position)
end
end
end
end
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(walk)
end)
(I did search but did not find anything that helped me and it normally had a distance limit.)
Also your code has a memory leak and overall bad practice, this will crash your server if your map is big and there are more than 5 players. Even lower than 5 players it will lag a lot.