Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I use an iterator to turn bool values to true one at a time?

So I am trying to make a game with fireworks, and want the fireworks to launch separately, and not at the same time. So I put the fireworks into a dictionary and am using in pairs(), however the script says it is an incomplete statement and was expecting an assignment or function call. I marked the problem area below, and I apologize for the very long inconvenient table.

local fireworks = game.Workspace.Fireworks
local fireworks = {					--sorry about this mess
	fireworki = fireworks.firework1,
	fireworkii = fireworks.firework2,
	fireworkiii = fireworks.firework3,
	fireworkiv = fireworks.firework4,
	fireworkv = fireworks.firework5,
	fireworkvi = fireworks.firework6,
	fireworkvii = fireworks.firework7,
	fireworkviii = fireworks.firework8,
	fireworkix = fireworks.firework9,
	fireworkx = fireworks.firework10,
	fireworkxi = fireworks.firework11,
	fireworkxii = fireworks.firework12,
	fireworkxiii = fireworks.firework13,
	fireworkxiv = fireworks.firework14,
	fireworkxv = fireworks.firework15,
	fireworkxvi = fireworks.firework16,
	fireworkxvii= fireworks.firework17,
	fireworkxviii = fireworks.firework18,
	fireworkxix = fireworks.firework19,
	fireworkxx= fireworks.firework20,
	fireworkxxi = fireworks.firework21
}
for i, v in pairs(fireworks) do
	v.Running == true --this is the problem
end

1 answer

✓ Accepted answer

Remove the extra equals sign to make it an assignment and not an equality comparison. To make the iteration easier, you should do two things.

  1. Put all fireworks in a folder. It seems you have already done this considering the Fireworks have the same parent called "Fireworks."

  2. Use GetChildren() to get a table of objects in that folder, and iterate through that table.

local fireworks = game.Workspace.Fireworks

for i, v in pairs(fireworks:GetChildren()) do
    v.Running = true --this is the problem
end

2 comments

0

Thank you! Also, is there an easier way to assign the fireworks than what I had to painstakingly write out?

0

Yes, I will update the code to explain how.

This discussion is preserved as it was. New answers, comments, and votes are closed.