So I am trying to program player fire damage, where every second, one point (for this example) is taken away from the player's health. I have programmed it to do damage if the UpperTorso (R15) has a Fire child. Here's what I have so far, in a LocalScript:
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local firetick = script.fire_tick.Value
local torso = char.UpperTorso
torso.ChildAdded:Connect(function(child)
if not child:IsA("Fire") then return end
print("Is a fire...")
while torso.Fire do --|1|
script.Parent.Humanoid.Health = script.Parent.Humanoid.Health - firetick
wait(1)
end
end)
I add a fire child using the Console in-game, and it works, but even after I call Destroy() on the fire, the damage continues? So that brings the question. How can I exit the while loop |1| after the child (child) is destroyed?
Edit: I updated the script, but it throws an error when it is destroyed.

1 comment
I should also mention that this script is in StarterPlayerScripts, if that helps.