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
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
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.
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)
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
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!
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!!