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