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

How to make a part's property change when all NPCs in a place are dead?

I'm making a zombie game (generic, I know) that "spawns" a boss zombie when all the other zombies are dead. The boss is floating in the air. All of his parts are transparent, and his torso is anchored. The script should make him visible and un-anchor the torso. Thing is: my script isn't working, and I can't find out why. Please help me. Here's the script:

local z1 = game.Workspace.Zombie1
local z2 = game.Workspace.Zombie2
local z3 = game.Workspace.Zombie3
local z4 = game.Workspace.Zombie4
local z5 = game.Workspace.Zombie5
local z6 = game.Workspace.Zombie6
local z7 = game.Workspace.Zombie7
local boss = game.Workspace["Boss Zombie"]
while z1.Zombie.Humanoid.Health == nil and z2.Zombie.Humanoid.Health == nil and z3.Zombie.Humanoid.Health == nil and z4.Zombie.Humanoid.Health == nil and z5.Zombie.Humanoid.Health == nil and z6.Zombie.Humanoid.Health == nil and z7.Zombie.Humanoid.Health == nil do
	wait()
	boss.Torso.Anchored = false
	boss.Torso.Transparency = 0
	boss.Head.Transparency = 0
	boss.zarm.Transparency = 0
	boss.rarm.Transparency = 0
	boss["Left Leg"].Transparency = 0
	boss["Right Leg"].Transparency = 0
	boss.Torso.CanCollide = true
	boss.Head.CanCollide = true
	boss.zarm.CanCollide = true
	boss.rarm.CanCollide = true
	boss["Left Leg"].CanCollide = true
	boss["Right Leg"].CanCollide = true
end

1 answer

Try using the died event

The died event is an event for Humanoids, and it fires when they die.

Game Plan

What I'm suggesting, is looping through all the zombies, setting up an event, and whenever one dies, decrease a number until it reaches 0. When is does reach 0, fire a function and then add your code. Easy Peas-z.

local num = 7
local boss = game.Workspace["Boss Zombie"]

local function SummonBoss()
	boss.Torso.Anchored = false
	boss.Torso.Transparency = 0
	boss.Head.Transparency = 0
	boss.zarm.Transparency = 0
	boss.rarm.Transparency = 0
	boss["Left Leg"].Transparency = 0
	boss["Right Leg"].Transparency = 0
	boss.Torso.CanCollide = true
	boss.Head.CanCollide = true
	boss.zarm.CanCollide = true
	boss.rarm.CanCollide = true
	boss["Left Leg"].CanCollide = true
	boss["Right Leg"].CanCollide = true
end

for i = 1,7 do
	local zombie = workspace:FindFirstChild("Zombie"..i)
	zombie.Humanoid.Died:connect(function()
		num = num-1
		if num == 0 then
			SummonBoss()
		end
	end
end
This is just a rough draft, basically. It might work, but it'll probably need some tweaking.

Good Luck

If you need anything explained, just ask. If I helped, or answered your question, then please don't forget to accept my answer.

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