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

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

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!

2 comments

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.

1

ZP1 is a part

1 answer

✓ Accepted answer

(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()"]

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