Only one part is inserted into the table

I’m trying to insert all of the clones of LightBullet into LightBulletTable, The problem is that for some reason only one LightBullet ends up inside the table, despite the for loop being there. How would I fix this?


This is the result that I get after printing the table once the for loop is done.

3 Likes

LightBullets and FinalBulletAmount are set to 1 so it only loops and inserts it to the LightBulletTable 1 time.

FinalBulletAmount isn’t set to 1, the 1 there is how much LightBullets increases by each loop. The loop loops 7 times and I can tell because all 7 of the bullets spawn and get positioned correctly. Unless I’m severely mistaking something here?

Sorry I saw it wrong but try removing the “, 1” after the FinalBulletAmount in the loop.
IMG_20240217_092235

Nothing changes, I guess the 1 was useless but the table still only gets one bullet inside of it.

Try parsing the “LightBullets” value in the loop from a outside loop defined value like the “FinalBulletAmount” and remove the “LightBullets = 1,” from the loop.

That makes roblox expect me to put “in” and then I’ll have to use pairs or ipairs, the problem isn’t that the loop only loops once, the problem is that only ONE bullet is getting inserted into LightBulletTable, despite the loop working fine.

1 Like

Alright I see, then your code seems okay. I think If the loop is looping 7 times fine it should also Clone the Part in the Moved folder in the ServerStorage. Does that also work fine?

It clones fine and everything, it just doesn’t insert 7 of them into the table, only the last one created seems to be getting inserted.

could you try adding the below line above the table.insert.

wait(.1)

Nothing changed, still only one bullet is inserted into the table.

Okay, give me some more time copying the code and finding a solution in a local testing place.

This is because LightBulletTable gets relooped everytime as an empty table. So put LightBulletTable above the for loop

1 Like

Move the table outside the loop

1 Like

And I’m sorry. Somehow I thought the whole time that the table wasn’t in the loop.

1 Like

Alright, thank you for the help!

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