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

How do I check if there's a specific children in Workspace?

Asked by 6 years ago

I'm trying to make a Boss spawn system, When all the regular zombies dies it spawns the boss.

This is the script i'm using:

if game.Workspace:FindFirstChild("Zombie") == nil then --Zombie is the regular zombie
    print("No Zombie") --Prints No Zombie
end

I dont know why it's not working so please help me, I dont need the boss spawning because I know how to make it.

Thanks, MajinBluee

0
Ohhh I know why it's not working, But thanks to you all who wanted to help me. MajinBluee 80 — 6y

3 answers

Log in to vote
2
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Instead of a loop, you can use the ChildRemoved event.

example:

workspace.ChildRemoved:connect(function(instance)
    local children = workspace:GetChildren()
    for i = 1, #children do 
        if (children[i].Name == "Zombie") then 
            print("there are " .. i .. " zombies left")

        elseif not workspace:FindFirstChild("Zombie") then 
            print("no zombies left")
        end
    end
end)

If you prefer a loop:

repeat wait(1)
    print("zombies still alive")
until not workspace:FindFirstChild("Zombie")
0
the print("there are "..i.." zombies left") isn't going to display the correct number, just saying. RubenKan 3615 — 6y
0
print(#children[i]) awesomeipod 607 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
repeat wait()
if game.Workspace:FindFirstChild("Zombie") == nil then
    print("No Zombies")
end
until game.Workspace:FindFirstChild("Zombie") ~= nil
print("Zombie!")
0
It doesn't work :( MajinBluee 80 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
while wait() do
    if game.Workspace:FindFirstChild("Zombie") == nil then
        print("No Zombie")
    end
end

Let me tell you why... Cuz your code has detect once and detect in a little little moment xD Hope its helped you!

0
It doesn't work :( MajinBluee 80 — 6y

Answer this question