Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Zombie Script Problem?

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago

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
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? fight4money -2 — 10y
0
Change everything in the sword script that has humanoid in the name of the humanoid of the zombie which is zombie. laughablehaha 494 — 10y
0
Thx!!! fight4money -2 — 10y
0
No problem :D laughablehaha 494 — 10y
Ad

Answer this question