Repeat until loop checked value not updating

So I’ve got this repeat until loop that check if the amount of children of a table of a module are 0. The weird thing is that it just doesn’t update. Only once at the beginning. If I remove children from the table while the loop is running it won’t print out the new amount of children. Just the amount that was in the table at the loop’s start.

for waveIndex = 1, #foundLayout do -- loop through wave
--stuff
		
		for enemyTypeIndex = 1, #waveData["Enemies"] do -- loop through enemy data
-- more stuff
		repeat task.wait(1) -- THE LOOP!!!!

		until #enemyConstructor.Enemies <= 0 
	end

Bildschirmfoto 2024-12-13 um 21.44.45

It’s seen in the image again. The loop gives out 0 but in reality the table has way more children.

1 Like

Looking at your output there, I would assume that #waveData["Enemies"] (or whatever the outputted array is) is outputting 0 because it isn’t starting at index 1.

A simple way to get the length of an array that isn’t starting at 1 is to use a function like this

function GetLength(Array: table)
	local Length = 0
	for _, _ in Array do
		Length += 1
	end
	return Length
end
2 Likes

This is most likely because you’re using brackets instead of table.insert() and table.remove()
#my_table only works for arrays. That means number keys starting at 1.

my_table[index] = my_value

You should be setting and removing the values like this:

table.insert(my_table, my_value)
local my_value = table.remove(my_table) -- Returns last value in array
-- Or
table.remove(my_table, index)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.