How To Remove Fire from All Players?

I need a working function to remove Fire from all Players when returning to the Lobby.

Here’s my current Function, which is not working:

function removeFire()
	local players = game.Players:GetPlayers()
	for _, Instance in pairs(players:GetDescendants()) do
		if Instance:IsA("Fire") then
		Instance:ClearAllChildren()
		end
	end
end 

Any help greatly appreciated :slight_smile:

2 Likes

First of all, why would you put a fire in the player? Second, ClearAllChildren clears everything without any exception, do Destroy.

Probably for an effect, that’s the point of fire.

To answer your question, you could just iterate through all the players’ characters and remove fire from them.
The following code should work just fine:

function removeFire()
    for _,plr in pairs(game.Players:GetChildren()) do -- iterate through players
        if plr.Character then -- Make sure they have a character
            for _,d in pairs(plr.Character:GetDescendants()) do
                if d:IsA("Fire") then d:Destroy() end -- remove all fire descendants of the character
            end
        end
    end
end
2 Likes

What you are doing is wrong. Your function first gets all descendants of a player, not even their character and then it checks if any Fire Instance exists and if it does it clears it’s children instead of destroying the instance itself.

I’d suggest reading @Vmena’s reply as well as he has provided some code aswell.

2 Likes

Thanks for the help!
Not sure why it’s not working. I got an error for the line:
“for _,plr in pairs(game.Players:GetChildren() do”
but adding another “)” at the end seemed to resolve that.
Still, when the players return to the lobby, the “Fire” particles are still emitting.

Not sure if it matters, but here is the code I use to set the “fire” (really just a green particle effect):

function lightOnFire(part)
print("Lighting on fire!")
print(part.Name)
local fire = Instance.new("ParticleEmitter")
fire.Texture = "rbxassetid://37332909"
fire.Size = NumberSequence.new(0.01,0.04)
fire.Rate = 6
fire.Lifetime = NumberRange.new(1,1.5)
fire.Speed = NumberRange.new(0, 1)
fire.SpreadAngle = Vector2.new(10,50)
fire.Color = ColorSequence.new(Color3.new(0,170,0))
fire.Parent = part

end

fireCollision = script.Parent 
fireCollision.Touched:connect(handleTouch)
fireCollision.Touched:connect(lightOnFire)

Yeah, you forgot to close the pairs(), and having the getchildren() probably made it seem like you had already

Okay, try this:

function lightOnFire(part)
print("Lighting on fire!")
print(part.Name)
local fire = Instance.new("ParticleEmitter")
fire.Name = "Fire" -- this is what line I added, naming so we know what to remove
fire.Texture = "rbxassetid://37332909"
fire.Size = NumberSequence.new(0.01,0.04)
fire.Rate = 6
fire.Lifetime = NumberRange.new(1,1.5)
fire.Speed = NumberRange.new(0, 1)
fire.SpreadAngle = Vector2.new(10,50)
fire.Color = ColorSequence.new(Color3.new(0,170,0))
fire.Parent = part

end

fireCollision = script.Parent 
fireCollision.Touched:connect(handleTouch)
fireCollision.Touched:connect(lightOnFire)
function removeFire()
    for _,plr in pairs(game.Players:GetChildren()) do -- iterate through players
        if plr.Character then -- Make sure they have a character
            for _,d in pairs(plr.Character:GetDescendants()) do
                if d.Name == "Fire" then d:Destroy() end -- remove all descendants named "Fire" from the character
            end
        end
    end
end
1 Like

You’re missing the .Character part. If you try to do it without the character instance it’ll throw this error: Index nil with player or something like that. Which means the instance you’re indexing will return nil and doesn’t exist.

You are a life saver! :slight_smile:
I’ve been trying to sort that out for days now!
As you can tell, I’m extremely new to scripting, but I love it, and every little bit helps.
Thanks!!

1 Like

Yeah but wouldn’t it not be visible since it needs to be in the Workspace?

It’s parented into the part which is in workspace.