So basically I want all the parts named "Fire" which have a fire in it and I want to have it all at the same time
Here is the script
local fire = script.Parent.Fire for i,v in pairs(script.Parent:GetChildren(fire)) do while true do wait(5) script.Parent:FindFirstChild('Fire') if v.Fire.Enabled == false then wait(math,Random(1 , 10)) v.Fire.Enabled = true end end end
the rest is pretty self-explanatory
The GetChildren
function returns a table consisting of the descendants of the object you used the function on. No arguments are needed. So, the children of 'fire' would be 'fire:GetChildren()'.
You also need to swap your loops - so that the for loop is running inside of the while loop. Otherwise the while loop will only affect the first descendant(since it is endless).
Note : Yielding the code inside of the for loop will cause latency between iterations. Look into using the thread scheduler, or coroutines
local fire = script.Parent.Fire while wait(5) do --'wait(5)' is truthy, and will still execute. for i,v in pairs(fire:GetChildren()) do --iterate through table local f = v:FindFirstChild("Fire") --find the fire object f.Enabled = true --Change the Enabled property end end
This should do the trick:
local function startFires(instance) for _, descendant in pairs(instance:GetDescendants()) do if descendant:IsA("Fire") then descendant.Enabled = true end end end -- You can change script.Parent to whatever instance you want startFires(script.Parent)