Menu
CoddyTech

Gagnants

Leçon 8 sur 18 du cours Jeu Roblox : Survivre aux catastrophes de Coddy.

Survivre à une manche rapporte une victoire. À la fin de la manche, chaque joueur encore dans survivors en gagne une :

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

+= ajoute une valeur directement. Pour savoir si quelqu’un a survécu, next(survivors) renvoie la première clé de la table, ou nil si elle est vide.

Les joueurs ont besoin d’un moment pour lire le résultat avant que le compte à rebours du lobby ne reprenne le tableau ; la manche se termine donc par task.wait(3).

challenge icon

Défi

Moyen

À la fin de la manche :

  1. Donne +1 Wins à chaque survivant (au lieu de les compter).
  2. Après la destruction de la carte, affiche Survivors win! si quelqu’un a survécu, ou Nobody survived! si personne n’a survécu.
  3. Attends 3 secondes avant le prochain compte à rebours dans le lobby.

Clique sur Jouer, survis à une manche et regarde tes Wins, puis clique sur Vérifier.

Essayez vous-même

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")

-- Chaque joueur reçoit des Wins dans le classement
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)

-- Le panneau d’état dans le hall
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

-- La boucle des manches
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 iconTestez-vous

Cette leçon comprend un petit quiz. Commencez la leçon pour y répondre et suivre votre progression.

Toutes les leçons de Jeu Roblox : Survivre aux catastrophes