Right now, your code would loop every second and check if the array that GetChildren() returns does not exist, hence "nil". Since the array does in fact exist, the condition in the if statement will always be false.
The GetChildren() function "returns an array containing all of the instance's direct children."
https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren
I'm going to assume that when a zombie is killed, it is also destroyed. To find the number of zombies left, we can use the length of table (#) operator.
while true do
if #workspace.Zobies.GetChildren() == 0 then
print("all zombies where killed")
end
task.wait()
end
I'm also going to assume that you want to have some kind of a round-based system. For this, all I added was the round variable to the while loop and some wait logic to start the round again.
local function doRound()
local round = true
while round do
if #workspace.Zobies:GetChildren() == 0 then
print("all zombies where killed")
round = false
end
task.wait()
end
print("Intermission | Round starting in 15 seconds")
task.wait(15)
print("Round started")
round = true
end
Well, here you go, hope this helps.
1 comment
So i tested the first one, but it never printed anything. I have the script placed in workspace, should it be placed somewhere else?