Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make all part have fire?

Asked by 7 years ago
Edited 7 years ago

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

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? WillieTehWierdo200 966 — 7y
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. The_sandwic 14 — 7y

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
Ad
Log in to vote
0
Answered by 7 years ago

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)

Answer this question