-- ==========================================
-- AULA 08.1: INTERFACE DE GAME OVER
-- ==========================================

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Encontrar o evento do jogo
local evento = ReplicatedStorage:WaitForChild("EventoJogo")

local interface = script.Parent
interface.ResetOnSpawn = false

-- ==========================================
-- CONTADOR DE VIDAS
-- ==========================================

local textoVidas = Instance.new("TextLabel")

textoVidas.Name = "TextoVidas"
textoVidas.Size = UDim2.new(0, 180, 0, 50)
textoVidas.Position = UDim2.new(0, 20, 0, 20)
textoVidas.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
textoVidas.TextColor3 = Color3.fromRGB(255, 255, 255)
textoVidas.TextScaled = true
textoVidas.Text = "Vidas: 3"
textoVidas.Parent = interface

-- ==========================================
-- PAINEL GAME OVER
-- ==========================================

local painel = Instance.new("Frame")

painel.Name = "PainelGameOver"
painel.Size = UDim2.new(1, 0, 1, 0)
painel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
painel.BackgroundTransparency = 0.3
painel.Visible = false
painel.Parent = interface

-- Texto GAME OVER
local titulo = Instance.new("TextLabel")

titulo.Name = "TituloGameOver"
titulo.Size = UDim2.new(0.8, 0, 0, 80)
titulo.Position = UDim2.new(0.1, 0, 0.3, 0)
titulo.BackgroundTransparency = 1
titulo.Text = "GAME OVER!"
titulo.TextColor3 = Color3.fromRGB(255, 50, 50)
titulo.TextScaled = true
titulo.Font = Enum.Font.GothamBold
titulo.Parent = painel

-- ==========================================
-- BOTAO RESTART
-- ==========================================

local botao = Instance.new("TextButton")

botao.Name = "BotaoRestart"
botao.Size = UDim2.new(0, 200, 0, 60)
botao.AnchorPoint = Vector2.new(0.5, 0.5)
botao.Position = UDim2.new(0.5, 0, 0.55, 0)
botao.BackgroundColor3 = Color3.fromRGB(0, 180, 80)
botao.TextColor3 = Color3.fromRGB(255, 255, 255)
botao.Text = "RESTART"
botao.TextScaled = true
botao.Font = Enum.Font.GothamBold
botao.Parent = painel

-- ==========================================
-- ATUALIZAR VIDAS E MOSTRAR GAME OVER
-- ==========================================

evento.OnClientEvent:Connect(function(acao, vidas)

	if acao == "Vidas" then

		textoVidas.Text = "Vidas: " .. vidas

		if vidas <= 0 then

			-- Mostrar Game Over
			painel.Visible = true

		else

			-- Esconder Game Over
			painel.Visible = false
			botao.Text = "RESTART"
			botao.Active = true
		end
	end
end)

-- ==========================================
-- CLICAR NO BOTAO RESTART
-- ==========================================

botao.Activated:Connect(function()

	-- Evitar clicar varias vezes
	if not botao.Active then
		return
	end

	botao.Active = false
	botao.Text = "A REINICIAR..."

	-- Pedir ao servidor para reiniciar
	evento:FireServer("Restart")
end)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: