I have a Zombie I scripted. The zombie can not be killed by players. Help?
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end function Hit(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human ~= nil then human.Health = human.Health -12 end end larm.Touched:connect(Hit) rarm.Touched:connect(Hit) while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Zombie:MoveTo(target.Position, target) end end
Check to see if your zombie's humanoid is actually named humanoid. I had a zombie scripted like this too and it is perfectly fine. Just make sure that the zombie's humanoid is named humanoid, not zombie. A player's weapon is usually set to damage a humanoid named humanoid, not a humanoid named zombie.
Hope this helped!
Change the script to this.
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end function Hit(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human ~= nil then human.Health = human.Health -12 end end larm.Touched:connect(Hit) rarm.Touched:connect(Hit) while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end