#The Problem The zombie can move and target the player correctly but it only targets that specific player throughout the whole game. Even when the player dies it waits and ignores all other players and when the specific player respawns it starts attacking that same player again.
#My Code The "zombie" is a single part that is a zombie body mesh.
local me = script.Parent
function FindNearestTorso() --Problem function
local on = false
for _,plyr in pairs(game:GetService("Players"):GetPlayers()) do
if plyr then
on = true
local char = plyr.Character
local h = char:FindFirstChild("Humanoid")
local t = char:FindFirstChild("Torso")
local max = 1000
closest = 0
if h and t and h.Health > 0 then
local mag = (me.Position - t.Position).magnitude
if mag < max then --Problem here maybe??
closest = t
max = mag
end
end
end
end
if on then
return closest
else
return 0 --No Torso
end
end
while wait() do
if type(FindNearestTorso()) ~= "number" then
me.CFrame = me.CFrame:lerp(FindNearestTorso().CFrame,.1) --Not the best way to move it... Any ideas?
end
end
Hope it helps!
