המנצחים
שיעור 8 מתוך 20 בקורס משחק Roblox: הישרדות באסונות של Coddy.
הישרדות בסיבוב שווה ניצחון. כשהסיבוב מסתיים, כל שחקן שעדיין נמצא ב-survivors מקבל אחד:
for player in survivors do
player.leaderstats.Wins.Value += 1
end+= מוסיף לערך במקום. כדי לבדוק אם מישהו שרד, next(survivors) מחזיר את המפתח הראשון בטבלה, או nil כשהיא ריקה.
השחקנים צריכים רגע כדי לקרוא את התוצאה לפני שספירת הזמן לאחור בלובי מחזירה את הלוח, לכן הסיבוב מסתיים ב-task.wait(3).
אתגר
בינוניתן לכל שורד ניצחון.
- כשהסיבוב מסתיים, הוסף 1 ל-
Winsשל כל שורד במקום לספור אותם. - אחרי שהמפה מושמדת, הצג
Survivors win!אם מישהו שרד, אחרת הצגNobody survived! - לאחר מכן,
task.wait(3)לפני הספירה לאחור הבאה בלובי.
לחץ על שחק ושרוד סיבוב: הערך של Wins יעלה ל-1 והלוח יציג Survivors win. לאחר מכן לחץ על בדיקה.
נסו בעצמכם
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")
-- כל שחקן מקבל Wins בטבלת המובילים
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)
-- לוח הסטטוס בלובי
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
-- לולאת הסבבים
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()
-- שיעור 8: הקוד של Winners נכנס כאן
print("Survivors: " .. count)
end
כל השיעורים ביחידה משחק Roblox: הישרדות באסונות
תרגלו בעצמכם: Roblox אונליין