this script i have has no errors i checked through it using print and everything is being run but its still not working
local zombie = script.Parent
local root = zombie:WaitForChild('HumanoidRootPart')
local humanoid = zombie:WaitForChild('Humanoid')
local players = game:GetService('Players')
local function nearestPlayer()
local temp = nil
local distance = 100
for _,plr in pairs(players:GetPlayers()) do
if plr then
local character = plr.Character
if character then
local h = character:FindFirstChildWhichIsA('Humanoid')
if h and h.Health > 0 then
local r = character:FindFirstChild('HumanoidRootPart')
if r then
local dist = (r.Position - root.Position).Magnitude
if dist < distance then
print("humanoids found")
distance = dist
temp = r
end
end
end
end
end
end
end
humanoid.Touched:Connect(function(hit)
local h = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if h and h.Health then
h:TakeDamage(10)
end
end)
while true do
game:GetService('RunService').Heartbeat:Wait()
local r = nearestPlayer()
if r then
humanoid:MoveTo(r.Position)
end
end