Can u set 2 things for 1 variable?

So, i was wondering if these a way for settings 2 things for a variable, like:
Normally u use local pizza = game.Workspace:WaitForChild("Pizza") or idk u dont need to use WaitForChild, but it was wondering if theres a way to make it for 2 objects like local building = game.Workspace:WaitForChild("Building1, Building2") is there a way to do that?

local Buildings = {
    Building1 = workspace:WaitForChild("Building1"),
    Building2 = workspace:WaitForChild("Building2")
}

print(Buildings.Building1, Buildings.Building2)

we can do this by making a table with both of the buildings

Ohh u can also use tables for that, but is there a way to get them just from 1 variable, like for a particle system (which is what im actually doing) theres 4 particles, so can i set 1 variable for all those 4 particles so i can only use it in 1 line like Particles.Enabled = true, idk if i explained well

You can loop through the table and enable each particle individually

local Particles = {
    Particle1 = workspace:WaitForChild("Particle1"),
    Particle2 = workspace:WaitForChild("Particle2"),
    Particle3 = workspace:WaitForChild("Particle3"),
    Particle4 = workspace:WaitForChild("Particle4")
}

for i,v in pairs(Particles) do
    v.Enabled = true
end

ohh this worked, thx!

character69420

You wouldn’t even need multiple variables for this, you could simply cycle through each instance inside the workspace.

for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("ParticleEmitter") then
		v.Enabled = true
	end
end

It would probably be way much more performant to either store it in a variable before runtime, or iterating through the workspace once and Inserting into a table, then iterating through the particles table to change their Enabled state.

1 Like

It was just a generic solution, it can of course be fine tuned by placing the particle emitters inside their own model/folder & then just getting the children/descendants of that instead.

1 Like