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

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

Asked by 8 years ago

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:

01local z1 = game.Workspace.Zombie1
02local z2 = game.Workspace.Zombie2
03local z3 = game.Workspace.Zombie3
04local z4 = game.Workspace.Zombie4
05local z5 = game.Workspace.Zombie5
06local z6 = game.Workspace.Zombie6
07local z7 = game.Workspace.Zombie7
08local boss = game.Workspace["Boss Zombie"]
09while 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
10    wait()
11    boss.Torso.Anchored = false
12    boss.Torso.Transparency = 0
13    boss.Head.Transparency = 0
14    boss.zarm.Transparency = 0
15    boss.rarm.Transparency = 0
View all 24 lines...

1 answer

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

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.

01local num = 7
02local boss = game.Workspace["Boss Zombie"]
03 
04local function SummonBoss()
05    boss.Torso.Anchored = false
06    boss.Torso.Transparency = 0
07    boss.Head.Transparency = 0
08    boss.zarm.Transparency = 0
09    boss.rarm.Transparency = 0
10    boss["Left Leg"].Transparency = 0
11    boss["Right Leg"].Transparency = 0
12    boss.Torso.CanCollide = true
13    boss.Head.CanCollide = true
14    boss.zarm.CanCollide = true
15    boss.rarm.CanCollide = true
View all 28 lines...
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.
Ad

Answer this question