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

How to make all part have fire?

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

2 comments

0

It's still unclear to me what you want. Do you just want every single part under script.Parent to have fire, and you want all the fire to be added at the same time?

0

So I named a few brick named Fire right. I added a fire in each one and turned off enabled. Now I want this script to find all of them and enable them at the same time.

2 answers

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)

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