Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Zombie Script Problem?

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

1 answer

✓ Accepted answer

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

4 comments

0

But multiple zombies will then kill each other! I kept the zombie's as Zombies, how would I change the sword script to make it be able to kill zombies?

0

Change everything in the sword script that has humanoid in the name of the humanoid of the zombie which is zombie.

0

Thx!!!

0

No problem :D

This discussion is preserved as it was. New answers, comments, and votes are closed.