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

How would I detect when the Zombie dies in my script?

Asked by 4 years ago
local zombie = script.Parent
local Humanoid = zombie:WaitForChild("Zombie")

while Humanoid.Health < 1 do   --I tried Humanoid.Died too
    wait(0.1)
    game.Workspace.ZP1.CanCollide = true
    break
end

The script above is supposed to change CanCollide on a part to true, so that another script can recognize that and award all players accordingly, but it doesnt change CanCollide on the part to true. It also doesn't display any errors. Help would be appreciated!

0
What is ZP1? shouldnt you just use the "zombie" as your model? since you're also scanning the MODEL and not any parts of the zombie, there is no such thing as cancollide. speedyfox66 237 — 4y
1
ZP1 is a part Trisodin529 89 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

(I've heard theres some errors with .Died not working, but i think if you properly code it right it will work.)

my take to the script:

local zombie = script.Parent
local Humanoid = zombie:WaitForChild("Zombie")

Humanoid.Died:Connect(function()
    wait(0.1)
    local g = zombie:GetChildren()
     for _,v in pairs(g) do
        if (v:IsA("BasePart")) then
        v.CanCollide = true
        end 
    end
end)

you should always check for the children of the zombie and not the zombie for CanCollide itself.

[KEEP IN MIND: Anything that is supposed to damage the zombie that finds the humanoid by name may not do anything and throw an error since your humanoid's name is Zombie, and maybe the scripter of whatever is giving damage didnt use "FindFirstChildOfClass()" and instead used "FindFirstChild()"]

Ad

Answer this question