I have this script for a zombie to find the closest person and chase him, but the findNearestTarget() function is not working. there is nothing in the output, please help!!
local player = script.Parent local followingPath = false torso = script.Parent.Torso range = 500 target = nil function findNearestTarget() for _, plr in pairs(game.Players:GetPlayers()) do if plr.Character ~= nil then tor = plr.Character.Torso if target ~= nil then if not target or (torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then target = plr.Character break end end end end end while true do wait(.1) findNearestTarget() if target~=nil then script.Parent.tar.Value = Vector3.new(target.Torso.Position) end end while true do if not followingPath then followingPath = true path = game:GetService("PathfindingService"):ComputeRawPathAsync(player.Torso.Position, script.Parent.tar.Value, 500) points = path:GetPointCoordinates() game.Workspace.Points:ClearAllChildren() for p = 1, #points do local part = Instance.new("Part") part.Size = Vector3.new(1, 1, 1) part.Position = points[p] part.Anchored = true part.CanCollide = false part.Parent = game.Workspace.Points end for _, point in pairs(points) do script.Parent.Zombie:MoveTo(point) repeat distance = (point - player.Torso.Position).magnitude wait() until distance < 3 end followingPath = false end wait(0.1) end
Replace Line 12
with this:
if not target or (torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then
i just made a free model for someone in the group to use its a alien that can chase and kill and be killed with guns / swords. u can change the looks to make it look like a zombie , i hope this helps.
http://www.roblox.com/alien-for-kid-item?id=174207024