Not resetting on death due to void

Hello! I have a system where it detects if the players’ health is less than or equal to 0. If it is, it fires a remote event and resets their GUI to the correct stuff related to the game. It works only if the player presses R. However, I want to make it work when the player dies by the void as well though.

I tried making it a function as I thought the if statement that was once in the 0.1 seconds while loop was not checking the if statement during the 0.1 seconds it was not running. However, this didn’t seem to work.

Does anyone know why this is happening? Here is my code:

local player = game.Players.LocalPlayer
local character = player.Character
local Humanoid = player.Character:WaitForChild("Humanoid")
local steps = player.PlayerGui.StepsGUI.Frame.TextLabel
local stagetrans = player.PlayerGui.StageTransfer.CurrentStage
local leaderstats = player.leaderstats.Stage
local mod = script.Parent.StoreSteps
local RunService = game:GetService("RunService")
print(steps.Text)

local data = require(mod)

stagetrans:GetPropertyChangedSignal("Text"):Connect(function()
	steps.Text = tostring(data[stagetrans.Text])
end)

RunService.RenderStepped:Connect(function(dt)
	if Humanoid.Health <=0 then
		game.ReplicatedStorage.TPOnDeath:FireServer(stagetrans.Text)
		print("FIRED RESET OR DEATH TO VOID")
		steps.Text = tostring(data[stagetrans.Text])
	end
end)

while task.wait(.1) do
	local new = if tonumber(steps.Text) then steps.Text - 1 else 0

	if new <= 15 then
		steps.TextColor3 = Color3.new(0.866667, 0, 0.0156863)
		steps.Parent.ImageLabel.ImageColor3 = Color3.new(0.866667, 0, 0.0156863)
	elseif new > 15 then
		steps.TextColor3 = Color3.new(255,255,255)
		steps.Parent.ImageLabel.ImageColor3 = Color3.new(255,255,255)
	end

	if Humanoid.MoveDirection.Magnitude > 0.0005 then
		steps.Text = new
	end

	if new <= 0 then
		print('recognized')
		Humanoid.Health -=100
		game.ReplicatedStorage.TPOnDeath:FireServer(stagetrans.Text)
		print("FIRED STEPS EXPIRED")
		steps.Text = tostring(data[stagetrans.Text])
		break
		--Other conditions above in RunService.RenderStepped function.
	end
end

If I recall correctly, when a player’s character falls below the workspace part limit it is destroyed. You’d likely need to handle the Destroying event.

Does not work. I also tried the .Died function but it did not work.

Hey character added runs when player dies from void, idk if this helps. This also runs when player joins though!

player.CharacterAdded:Connect(function(char)
		print("HELO!")
end)

local function reset()
if Humanoid.Health <= 0 then
steps.Text = tostring(data[stagetrans.Text])
print(“FIRED STEPS EXPIRED”)
break
end
end

reset()

When I die to the void, the reset function fires, but nothing happens. If I press R, the system works as it should. I just want it to work on death too.
If you want to test, here is a link to the model that I have uploaded: daniala3111's Place - Roblox
If you need more context, I have uploaded a video to explain everything: - YouTube

You’re video is not available. Also I am confused.

You said pressing R works fine, but the death to void doesn’t? I want to achieve when death to void also works fine.