I have a zombie killing script, but they just kill anything with a humanoidrootpart, including eachother
how do I make it so that they can’t kill eachother?
The Script:
local larm = script.Parent:FindFirstChild("HumanoidRootPartZ")
local rarm = script.Parent:FindFirstChild("HumanoidRootPartZ")
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("HumanoidRootPart")
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
while true do
wait(math.random(1,5))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.HumanoidZ:MoveTo(target.Position, target)
end
end
while true do
wait(math.random(1,5))
local players = game.Players.PlayerAdded
local target = players.findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.HumanoidZ:MoveTo(target.Position, target)
end
end
local Players = game:GetService("Players")
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("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
if Players:GetPlayerFromCharacter(temp.Parent) then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
end
return torso
end
Sorry for the long wait, when I put I replaced this with the other function, the zombie just stood still. Thank you for your help though. I will keep trying.
can can also check if a humanoid is the humanoid form a player, using Players:GetPlayerFromCharacter(humanoid.Parent) ~= nil or players:FindFirstChild(Humanoid.Parent.Name) ~= nil
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
human.Health = human.Health - 100 -- Change the amount to change the damage.
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) and game.Players:FindFirstChild(hit.Parent.name) then --the small edit here makes the script only killing players
human.Health = human.Health - 100 -- Change the amount to change the damage.
end
end
script.Parent.Touched:connect(onTouched)