Okay, what’s the problem? I have a script that spawns t a certain point of the mob, this mob goes along the road, and when it reaches its end, it is removed from the folder Mobs. The script checks if this folder is empty, start the second wave, etc. But why, when the Mobs folder is empty, the new wave does not begin? It does not even write that the wave is over. What is the problem?
I think you can’t check if “:GetChildren()” is 0, because it returns you a table.
Try do this
until table.getn(workspace.MobsGetChildren()) == 0
I replaced the line, but it still didn’t make any difference
Here, look, I wrote this script, which checks if there are 1 or more monsters on the map, then print certain words, but as you can see nothing is shown. Does this mean that the check command itself does not work?
Before the repeat, try to find the size of the Mobs table using #
That’s it, if so, then everything is the same as in the last screenshot I sent you. That is, also spawns a mob on the first rampart, and print wave 1 began. Mob dies from the tower, and then everything. Nothing happens, neither the end of the wave nor the beginning of a new wave.
Its Strongly recommend you use backticks (```
) to format your code, this will make it so your code looks like this:
--- this is a code block using backticks: ```
--- Its Recommended to use this to make it easier to read
-- NOTE that its against the rules to be sending images of your code.
As for your Code, I’ll provide:
both table.getn()
and #Table
are the same thing, they return the amount of Items that are within the table. This is known as “Syntactic Sugar” where the Programming Language is designed to make it easier to code or express. But do note that table.getn()
is the “proper way” while #Table
is the Shortcut.
Instead of using an if
statement to check what wave it is, you can use the index
(or in this case wave
) to determine what mobs to spawn:
for wave = 1,5 do
print("Wave", wave)
wave.Spawn("Mech", wave, map) -- basically the same thing without the statements
Now, I see a bit of a problem with your code, You are telling the loop to repeat until
there is more than 1 mob within the Folder, this is an issue as it will automatically break when that happens, so i recommend reversing it:
repeat task.wait(1)
until table.getn(workspace.Mobs:GetChildren()) < 1 -- less than 1
local mob = require(script.Mob)
local map = workspace.map
for wave = 1, 5 do
print("WAVE STARTING", wave)
if wave == 1 then
mob.Spawn("Mech", 1, map)
end
if wave == 2 then
mob.Spawn("Mech", 2, map)
end
--repeat
-- task.wait(1)
--until #workspace.Mobs:GetChildren() == 0
----until table.getn(workspace.#MobsGetChildren()) == 0
repeat task.wait(1)
until table.getn(workspace.Mobs:GetChildren()) < 1
--print("It's not over.")
print("WAVE ENDED")
task.wait(1)
end
Okay, I changed the script like this, but again, nothing changed.
Write:
while table.getn(workspace.Mobs:GetChildren()) < 1 wait() print("Size of table is: " .. #(workspace.Mobs:GetChildren())
So, that’s it?
local mob = require(script.Mob)
local map = workspace.map
for wave = 1, 5 do
print("WAVE STARTING", wave)
if wave == 1 then
mob.Spawn("Mech", 1, map)
end
if wave == 2 then
mob.Spawn("Mech", 2, map)
end
--repeat
-- task.wait(1)
--until #workspace.Mobs:GetChildren() == 0
----until table.getn(workspace.#MobsGetChildren()) == 0
while table.getn(workspace.Mobs:GetChildren()) < 1 wait() print("Size of table is: " .. #(workspace.Mobs:GetChildren())
--print("It's not over.")
print("WAVE ENDED")
task.wait(1)
end
If it does, it gives this error
Also btw, looking at your ModuleScript
, you aren’t telling your mob to move, you are wrapping the code in a coroutine
, but not firing it.
You Should be doing:
coroutine.wrap(mob.Move)(newMob, map)
I don’t mean to copy my code literally because it is in a broken format (idk how to write code properly on the forums). But implement it into the game. You should basically be seeing what the value of that GetChildren() is, since it’s not < 1, it could be 2 or 3. You should also then check what those things in GetChildren() are using an enhanced for loop (ipairs). Once you have information you will have a much easier time solving the problem from there.
Putting # before it gets the number in the table
so #workspace.Mobs:GetChildren()
would return the number of mobs in the folder.
Add a BooleanValue that checks when #workspace.Mobs:GetChildren() > 0
. Wrap it in a loop and use GetPropertyChangedSignal for when the boolean is activated. Hope that helps.
if
statement’s already do this that by checking if the Value is true
or false
, Thats the whole Purpose of the if
in the if
statement
Are you positive they’re spawning correctly?
Yeah, it doesn’t yield though, like a repeat wait() function. It doesn’t wait until it changes, GetPropertyChangedSignal does.
The whole purpose of the repeat
loop inside the while true do
loop is to yield.
The repeat
loop is to prevent the game from moving forward, this is so the game can focus on the current round, until the condition is met, if there was no yielding, the loop would either crash the game, or continue the game with out stopping for each wave, What you’re saying to do is useless (if
statements and conditions already do this for you) and will end up causing this issue rather than fixing an issue like you intend.