Roblox · Обби · урок 5
Длинную полосу никто не пройдёт с начала после каждой ошибки. Чекпоинты запоминают этап, а таблица по Tab показывает, кто дальше всех.
Синим — что добавляем на этом уроке.
Workspace └─ Checkpoints (Folder) ├─ 0 (Part) — старт └─ 1, 2, 3… (Part) — чекпоинты по порядку ServerScriptService └─ Checkpoints (Script)
Где: ServerScriptService · Script
Зачем: Этапы игроков и появление на чекпоинте.
-- сервис игроков
local Players = game:GetService("Players")
-- папка с чекпоинтами 0, 1, 2…
local checkpoints = workspace:WaitForChild("Checkpoints")
-- игрок зашёл
Players.PlayerAdded:Connect(function(player)
-- таблица по Tab
local leaderstats = Instance.new("Folder")
-- имя строго такое
leaderstats.Name = "leaderstats"
-- в игрока
leaderstats.Parent = player
-- номер этапа
local stage = Instance.new("IntValue")
-- столбец «Stage»
stage.Name = "Stage"
-- в таблицу
stage.Parent = leaderstats
-- персонаж появился (и после каждой смерти)
player.CharacterAdded:Connect(function(character)
-- Humanoid персонажа
local humanoid = character:WaitForChild("Humanoid")
-- ждём, пока персонаж соберётся
character:WaitForChild("HumanoidRootPart")
-- чекпоинт текущего этапа
local point = checkpoints:FindFirstChild(tostring(stage.Value))
-- нашёлся
if point then
-- даём Roblox закончить появление на SpawnLocation
task.wait(0.1)
-- ставим над чекпоинтом
character:PivotTo(point.CFrame + Vector3.new(0, 3, 0))
-- конец проверки
end
-- персонаж чего-то коснулся
humanoid.Touched:Connect(function(hit)
-- это следующий по номеру чекпоинт
if hit.Parent == checkpoints and tonumber(hit.Name) == stage.Value + 1 then
-- этап пройден
stage.Value += 1
-- конец проверки
end
-- конец функции
end)
-- конец функции
end)
-- конец функции
end)Запусти Play (или Run) и убедись:
Roblox · Obby · lesson 5
Nobody will finish a long course if they restart after every mistake. Checkpoints remember the stage, and the Tab board shows who got furthest.
Blue — what we add in this lesson.
Workspace └─ Checkpoints (Folder) ├─ 0 (Part) — start └─ 1, 2, 3… (Part) — checkpoints in order ServerScriptService └─ Checkpoints (Script)
Where: ServerScriptService · Script
Why: Player stages and respawning on the checkpoint.
-- the Players service
local Players = game:GetService("Players")
-- the folder with checkpoints 0, 1, 2…
local checkpoints = workspace:WaitForChild("Checkpoints")
-- a player joined
Players.PlayerAdded:Connect(function(player)
-- the Tab board
local leaderstats = Instance.new("Folder")
-- the name must be exactly this
leaderstats.Name = "leaderstats"
-- into the player
leaderstats.Parent = player
-- stage number
local stage = Instance.new("IntValue")
-- the "Stage" column
stage.Name = "Stage"
-- into the board
stage.Parent = leaderstats
-- the character spawned (also after every death)
player.CharacterAdded:Connect(function(character)
-- the character's Humanoid
local humanoid = character:WaitForChild("Humanoid")
-- wait until the character is assembled
character:WaitForChild("HumanoidRootPart")
-- the checkpoint of the current stage
local point = checkpoints:FindFirstChild(tostring(stage.Value))
-- found
if point then
-- let Roblox finish spawning on the SpawnLocation
task.wait(0.1)
-- place above the checkpoint
character:PivotTo(point.CFrame + Vector3.new(0, 3, 0))
-- end of check
end
-- the character touched something
humanoid.Touched:Connect(function(hit)
-- it's the next checkpoint by number
if hit.Parent == checkpoints and tonumber(hit.Name) == stage.Value + 1 then
-- stage passed
stage.Value += 1
-- end of check
end
-- end of function
end)
-- end of function
end)
-- end of function
end)Press Play (or Run) and make sure: