Saving Gui Upon Death

I’m new to scripting and I have a script that counts down from 60, the only thing is… whenever you die the counter resets, is there anyone that could help me out?

-Here’s the script

local text = game.StarterGui.Counter.TextLabel
print(text.Text)
– Number to count down from
local startNumber = 60

– When a player is added connect this function to it
game:GetService(“Players”).PlayerAdded:Connect(function(player)
local count = startNumber
while true do
– “count = count - 1” but compressed into “count -= 1”
count -= 1
– Text can’t be a number so turn it into a string
print(count)
text.Text = count
– If the new number is less than or equal to 0 kick the player
if count <= 0 then
player:Kick()
end
task.wait(1)
end
end)

A ScreenGui has a property called ResetOnSpawn and I assume game.StarterGui.Counter is a ScreenGui, maybe turning this off will fix this issue.

local text = game.StarterGui.Counter.TextLabel
print(text.Text)

local startNumber = 60

game:GetService("Players").PlayerAdded:Connect(function(player)
	local count = startNumber
	local countdownActive = true

	local function updateCounter()
		while countdownActive and count > 0 do
			count -= 1
			text.Text = tostring(count)

			if player.Character and player.Character:FindFirstChild("Humanoid") then
				task.wait(1)
			else
				countdownActive = false
			end
		end

		if count <= 0 then
			player:Kick()
		end
	end

	updateCounter()
end)

ill try it out and see if it works

thanks for the help! i’ve been stuck on the gui for awhile.

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