Menu
CoddyTech

Vincitori

Lezione 8 di 18 del corso Gioco Roblox: Sopravvivenza ai disastri di Coddy.

Sopravvivere a un round vale una Vittoria. Quando il round termina, ogni giocatore ancora in survivors ne ottiene una:

for player in survivors do
	player.leaderstats.Wins.Value += 1
end

+= aggiunge un valore direttamente a una variabile. Per verificare se qualcuno è sopravvissuto, next(survivors) restituisce la prima chiave della tabella oppure nil se è vuota.

I giocatori hanno bisogno di un momento per leggere il risultato prima che il conto alla rovescia della lobby riprenda il controllo della schermata, quindi il round termina con task.wait(3).

challenge icon

Sfida

Medio

Quando termina il round:

  1. Assegna +1 Wins a ogni sopravvissuto (invece di contarli).
  2. Dopo aver distrutto la mappa, mostra Survivors win! se qualcuno è sopravvissuto oppure Nobody survived! se non è sopravvissuto nessuno.
  3. Attendi 3 secondi prima del prossimo conto alla rovescia nella lobby.

Premi Gioca, sopravvivi a un round e guarda i tuoi Wins, poi premi Controlla.

Provalo tu

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)

local lobbySpawn = workspace.LobbySpawn

print("Rounds last " .. Settings.RoundLength .. " seconds")

-- Ogni giocatore ottiene Wins nella classifica
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- Il tabellone di stato nella lobby
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard

local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui

local function setStatus(text)
	status.Text = text
end

local function teleport(player, target)
	local character = player.Character
	if character then
		character:PivotTo(target.CFrame + Vector3.new(0, 4, 0))
	end
end

-- Il ciclo dei round
while true do
	for seconds = Settings.Intermission, 1, -1 do
		setStatus("Intermission: " .. seconds)
		task.wait(1)
	end

	local map = ServerStorage.Maps.Island:Clone()
	map.Name = "Map"
	map.Parent = workspace

	local survivors = {}
	for _, player in Players:GetPlayers() do
		local character = player.Character
		if character and character.Humanoid.Health > 0 then
			teleport(player, map.Spawn)
			survivors[player] = true
			character.Humanoid.Died:Connect(function()
				survivors[player] = nil
			end)
		end
	end

	for seconds = Settings.RoundLength, 1, -1 do
		setStatus("Time left: " .. seconds)
		task.wait(1)
	end

	local count = 0
	for player in survivors do
		count += 1
		teleport(player, lobbySpawn)
	end
	map:Destroy()
	print("Survivors: " .. count)
end
quiz iconMettiti alla prova

Questa lezione include un breve quiz. Inizia la lezione per rispondere e tenere traccia dei tuoi progressi.

Tutte le lezioni di Gioco Roblox: Sopravvivenza ai disastri