How to keep the text same after respawn?

Hello, I want to make it so that when the player runs out of steps, they die. I’ve got that part working but when they die, the steps counter resets back to the default 100 even though the stage sets it to be 25. How would I make it so that the steps is 25 and when they die its also 25, but also make it so that it works for any stage.

Heres an example of what I want: Player begins stage 1. Steps counter is 100. They run out and die, their step counter resets back to 100. Player begins stage 2. Step counter is 25 they run out and die. Their step counter is 25 when they respawn.

Heres an example of what’s happening right now: Player begins stage 1. Steps counter is 100. They run out and die, their step counter resets back to 100. Player begins stage 2. Step counter is 25 they run out and die. Their step counter is back to 100 when they respawn.

Here is my current code:

local player = game.Players.LocalPlayer
local Humanoid = player.Character:WaitForChild("Humanoid")
local steps = player.PlayerGui.StepsGUI.Frame.TextLabel
local stagetrans = player.PlayerGui.StageTransfer.CurrentStage
print(steps.Text)

stagetrans:GetPropertyChangedSignal("Text"):Connect(function()
	if stagetrans.Text == "0" then
		steps.Text = "9999999"
	elseif stagetrans.Text == "1" then
		steps.Text = "100"
	elseif stagetrans.Text == "2" then
		steps.Text = "75"
	elseif stagetrans.Text == "3" then
		steps.Text = "125"
	elseif stagetrans.Text == "4" then
		steps.Text = "25"
	
	end
end)

while task.wait(.1) do
	if Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
		local new = tonumber(steps.Text)-1
		local text = tostring(new)
		player.PlayerGui.StepsGUI.Frame.TextLabel.Text = text
		if new == 0 then
			Humanoid.Health -=100
			break
		elseif 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 >= 16 then
			steps.TextColor3 = Color3.new(255,255,255)
			steps.Parent.ImageLabel.ImageColor3 = Color3.new(255,255,255)
		end
	end
end
1 Like

if it’s a gui then makse sure resetondeath is off in properties

1 Like

When I do that and the player resets or dies, the counter doesn’t reset back and instead it goes into the negatives (which I don’t want).

1 Like

maybe when the player dies, you can save a value in the script by using ondeath function, and then apply it to the counter when the player respawns

1 Like

I did something similar to that, I used a check value in a while true loop and it worked. I forgot to close this topic. So sorry. Thank you for helping though!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.