(Reset on Spawn) for a local player

Hey everyone, as of right now I am working on a lives system and I want to link my gui to the lives.
when they hit 0 lives i want the gui to stay there (Reset on spawn) so they get a promt to buy more lives.

– This is the local script –
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local player = game:FindFirstChildWhichIsA(“Players”).LocalPlayer or game:FindFirstChildWhichIsA(“Players”).Players.PlayerAdded:Wait()
local LocalPlayer = game.Players.LocalPlayer

humanoid.Died:Connect(function()
wait(0.01)
Player.PlayerGui.DeathGui.Frame.Visible = true
if Player.Lives.Value == 2 then
Player.PlayerGui:FindFirstChild(“DeathGui”).Frame.Timer.Text = (“2 Remaining Lives.”)
wait(4.5)
Player.PlayerGui.DeathGui.Frame.Visible = false
end

wait(0.01)
Player.PlayerGui.DeathGui.Frame.Visible = true
if Player.Lives.Value == 1 then
	Player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = ("1 Remaining life.")
	wait(4.5)
	Player.PlayerGui.DeathGui.Frame.Visible = false
	game.Players.RespawnTime = 80.0
end

Player.PlayerGui.DeathGui.Frame.Visible = true
wait(0.000000001)
if Player.Lives.Value == 0 then
	Player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = ("Ran out of lives.")
end

end)

Thanks for the help!

Just posting this for the code to be easily read

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local player = game:FindFirstChildWhichIsA(“Players”).LocalPlayer or game:FindFirstChildWhichIsA(“Players”).Players.PlayerAdded:Wait()
local LocalPlayer = game.Players.LocalPlayer

humanoid.Died:Connect(function()
	wait(0.01)
	Player.PlayerGui.DeathGui.Frame.Visible = true
	if Player.Lives.Value == 2 then
		Player.PlayerGui:FindFirstChild(“DeathGui”).Frame.Timer.Text = (“2 Remaining Lives.”)
		wait(4.5)
		Player.PlayerGui.DeathGui.Frame.Visible = false
	end
	wait(0.01)
	Player.PlayerGui.DeathGui.Frame.Visible = true
	if Player.Lives.Value == 1 then
		Player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = ("1 Remaining life.")
		wait(4.5)
		Player.PlayerGui.DeathGui.Frame.Visible = false
		game.Players.RespawnTime = 80.0
	end

	Player.PlayerGui.DeathGui.Frame.Visible = true
	wait(0.000000001)
	if Player.Lives.Value == 0 then
		Player.PlayerGui:FindFirstChild("DeathGui").Frame.Timer.Text = ("Ran out of lives.")
	end
end)

Also, what issues are you facing with this code?

1 Like

This line,
I want to have a reset on spawn set to false here but it wont work in the script.

Player.PlayerGui.DeathGui.Frame.Visible = true
wait(0.000000001)
if Player.Lives.Value == 0 then
Player.PlayerGui:FindFirstChild(“DeathGui”).Frame.Timer.Text = (“Ran out of lives.”)
end
end)

Nvm I solved it thanks for trying though.

1 Like

FYI you could just use Wait() as the base time is like 0.03 seconds

1 Like

Thanks for the info I am designing a horror game lives system. And appreciate ur help.

1 Like