Roblox · Сбор-а-тон · урок 7
Итог курса на одной странице: полная структура сбор-а-тона и финальные версии всех скриптов. Удобно сверить свою игру или собрать её заново.
Синим — что добавляем на этом уроке.
Workspace — StreamingEnabled выкл. ├─ Map (Model) — зоны ├─ Items (Folder) │ └─ предмет (Part) — Decal, Difficulty, Description, BadgeID └─ Teleports (Folder) — площадки с Decal ReplicatedStorage └─ Events (Folder) — CollectEvent, GameOverEvent ServerScriptService └─ CollectServer (Script) StarterGui — все ResetOnSpawn выкл. ├─ CollectGui (ScreenGui) — Message, Found, CollectLocal ├─ ListGui (ScreenGui) — ListButton, ListFrame (Progress, SearchBox, ScrollingList → Sample), DescriptionFrame, TeleportButton, TeleportFrame, ListLocal, TeleportLocal └─ GameOverGui (ScreenGui) — GameOverFrame, GameOverLocal
Где: ServerScriptService · Script
Зачем: Находки, сохранение, конец игры.
-- игроки
local Players = game:GetService("Players")
-- общее хранилище
local RS = game:GetService("ReplicatedStorage")
-- сохранение
local DSS = game:GetService("DataStoreService")
-- нашивки (по желанию)
local BadgeService = game:GetService("BadgeService")
-- все предметы
local items = workspace:WaitForChild("Items")
-- события
local events = RS:WaitForChild("Events")
-- «нашёл предмет»
local collectEvent = events:WaitForChild("CollectEvent")
-- «нашёл всё»
local gameOverEvent = events:WaitForChild("GameOverEvent")
-- хранилище находок
local store = DSS:GetDataStore("CollectData")
-- у кого находки загрузились
local loaded = {}
-- сохранить находки
local function Save(player)
-- не загрузились — не затираем
if not loaded[player] then return end
-- имена найденных
local list = {}
-- каждая находка
for _, mark in ipairs(player.Found:GetChildren()) do
-- в список
table.insert(list, mark.Name)
-- конец перебора
end
-- сохраняем
pcall(function() store:SetAsync("found_" .. player.UserId, list) end)
-- конец функции
end
-- игрок нашёл предмет
local function Collect(player, item)
-- его находки
local found = player:FindFirstChild("Found")
-- уже нашёл
if not found or found:FindFirstChild(item.Name) then return end
-- отметка
local mark = Instance.new("BoolValue")
-- имя = предмет
mark.Name = item.Name
-- в папку игрока
mark.Parent = found
-- сообщение на экране
collectEvent:FireClient(player, item.Name)
-- ID нашивки
local badge = item:FindFirstChild("BadgeID")
-- нашивка настроена
if badge and badge.Value > 0 then
-- не задерживаем остальное
task.spawn(function()
-- выдаём; в Studio может не сработать
pcall(function() BadgeService:AwardBadge(player.UserId, badge.Value) end)
-- конец функции
end)
-- конец проверки
end
-- найдено всё
if #found:GetChildren() >= #items:GetChildren() then
-- через секунду — экран победы
task.delay(1, function() gameOverEvent:FireClient(player) end)
-- конец проверки
end
-- конец функции
end
-- игрок зашёл
local function Setup(player)
-- его находки
local found = Instance.new("Folder")
-- имя
found.Name = "Found"
-- загружаем
local ok, list = pcall(function() return store:GetAsync("found_" .. player.UserId) end)
-- загрузка удалась
if ok then
-- каждое сохранённое имя
for _, name in ipairs(list or {}) do
-- такой предмет ещё есть
if items:FindFirstChild(name) then
-- отметка
local mark = Instance.new("BoolValue")
-- имя
mark.Name = name
-- в папку
mark.Parent = found
-- конец проверки
end
-- конец перебора
end
-- можно сохранять
loaded[player] = true
-- конец проверки
end
-- в игрока — клиент видит
found.Parent = player
-- конец функции
end
-- новые игроки
Players.PlayerAdded:Connect(Setup)
-- кто зашёл раньше скрипта
for _, player in ipairs(Players:GetPlayers()) do task.spawn(Setup, player) end
-- игрок вышел
Players.PlayerRemoving:Connect(function(player)
-- сохраняем
Save(player)
-- забываем
loaded[player] = nil
-- конец функции
end)
-- сервер закрывается
game:BindToClose(function()
-- сохраняем всех
for _, player in ipairs(Players:GetPlayers()) do Save(player) end
-- конец функции
end)
-- каждый предмет — один раз
for _, item in ipairs(items:GetChildren()) do
-- клик
local clicker = item:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector")
-- кликнуть можно только рядом
clicker.MaxActivationDistance = 20
-- в предмет
clicker.Parent = item
-- кто-то кликнул
clicker.MouseClick:Connect(function(player)
-- засчитываем
Collect(player, item)
-- конец функции
end)
-- конец перебора
endГде: StarterGui → CollectGui · LocalScript
Зачем: Сообщение о находке.
-- общее хранилище
local RS = game:GetService("ReplicatedStorage")
-- «нашёл предмет»
local collectEvent = RS:WaitForChild("Events"):WaitForChild("CollectEvent")
-- CollectGui
local gui = script.Parent
-- надпись
local message = gui:WaitForChild("Message")
-- звук находки
local sound = gui:WaitForChild("Found")
-- номер последнего сообщения
local shown = 0
-- сервер засчитал находку
collectEvent.OnClientEvent:Connect(function(name)
-- новое сообщение
shown += 1
-- его номер
local my = shown
-- текст
message.Text = "Найдено: " .. name .. "!"
-- показываем
message.Visible = true
-- звук
sound:Play()
-- ждём
task.wait(2.5)
-- прячем, если не пришло новое
if shown == my then message.Visible = false end
-- конец функции
end)Где: StarterGui → ListGui · LocalScript
Зачем: Журнал, описание, поиск.
-- игроки
local Players = game:GetService("Players")
-- этот игрок
local player = Players.LocalPlayer
-- все предметы
local items = workspace:WaitForChild("Items")
-- что игрок уже нашёл
local found = player:WaitForChild("Found")
-- ListGui
local gui = script.Parent
-- кнопка журнала
local listButton = gui:WaitForChild("ListButton")
-- журнал
local listFrame = gui:WaitForChild("ListFrame")
-- список с прокруткой
local scrolling = listFrame:WaitForChild("ScrollingList")
-- шаблон карточки
local sample = scrolling:WaitForChild("Sample")
-- «Найдено: 2 / 6»
local progress = listFrame:WaitForChild("Progress")
-- поиск
local searchBox = listFrame:WaitForChild("SearchBox")
-- окно описания
local description = gui:WaitForChild("DescriptionFrame")
-- цвет сложности
local COLORS = {Easy = Color3.fromRGB(80, 220, 100), Medium = Color3.fromRGB(255, 150, 40), Hard = Color3.fromRGB(240, 60, 60)}
-- лёгкие — первыми
local ORDER = {Easy = 1, Medium = 2, Hard = 3}
-- найденная карточка
local FOUND_COLOR = Color3.fromRGB(150, 230, 120)
-- ещё не найденная
local HIDDEN_COLOR = Color3.fromRGB(60, 60, 75)
-- имя предмета → карточка
local cards = {}
-- перекрасить карточки и обновить счёт
local function Refresh()
-- сколько найдено
local count = 0
-- каждая карточка
for name, card in pairs(cards) do
-- найден ли предмет
local isFound = found:FindFirstChild(name) ~= nil
-- цвет
card.BackgroundColor3 = isFound and FOUND_COLOR or HIDDEN_COLOR
-- считаем
if isFound then count += 1 end
-- конец перебора
end
-- счёт
progress.Text = "Найдено: " .. count .. " / " .. #items:GetChildren()
-- конец функции
end
-- строчные буквы, включая русские
local function Lower(text)
-- буквы результата
local out = {}
-- каждая буква по номеру
for _, code in utf8.codes(text) do
-- А…Я
if code >= 1040 and code <= 1071 then
-- → а…я
code += 32
-- Ё
elseif code == 1025 then
-- → ё
code = 1105
-- конец проверки
end
-- в результат
table.insert(out, utf8.char(code))
-- конец перебора
end
-- латиница — обычным lower
return string.lower(table.concat(out))
-- конец функции
end
-- окно описания предмета
local function ShowDescription(item)
-- StringValue с описанием
local text = item:FindFirstChild("Description")
-- название
description.Title.Text = item.Name
-- предмет найден
if found:FindFirstChild(item.Name) then
-- описание
description.Body.Text = text and text.Value or ""
-- ещё нет
else
-- загадка
description.Body.Text = "Найди этот предмет, чтобы прочитать о нём."
-- конец проверки
end
-- показываем
description.Visible = true
-- конец функции
end
-- карточка на каждый предмет
for _, item in ipairs(items:GetChildren()) do
-- копия шаблона
local card = sample:Clone()
-- имя
card.Name = item.Name
-- подпись
card.ItemName.Text = item.Name
-- картинка предмета
local decal = item:FindFirstChildOfClass("Decal")
-- на кнопку
card.ItemImage.Image = decal and decal.Texture or ""
-- фон — цвет предмета
if item:IsA("BasePart") then card.ItemImage.BackgroundColor3 = item.Color end
-- сложность
local difficulty = item:FindFirstChild("Difficulty")
-- Easy, если не указана
local level = difficulty and difficulty.Value or "Easy"
-- полоска цвета сложности
card.Difficulty.BackgroundColor3 = COLORS[level] or COLORS.Easy
-- порядок в списке
card.LayoutOrder = ORDER[level] or 1
-- шаблон был скрыт
card.Visible = true
-- в список
card.Parent = scrolling
-- запоминаем
cards[item.Name] = card
-- клик — описание
card.ItemImage.MouseButton1Click:Connect(function() ShowDescription(item) end)
-- конец перебора
end
-- нашёл новый — обновляем
found.ChildAdded:Connect(Refresh)
-- сразу при входе
Refresh()
-- кнопка журнала
listButton.MouseButton1Click:Connect(function()
-- открыть / закрыть
listFrame.Visible = not listFrame.Visible
-- конец функции
end)
-- закрыть описание
description.CloseButton.MouseButton1Click:Connect(function()
-- прячем
description.Visible = false
-- конец функции
end)
-- ввели текст в поиск
searchBox:GetPropertyChangedSignal("Text"):Connect(function()
-- что ищем
local query = Lower(searchBox.Text)
-- каждая карточка
for name, card in pairs(cards) do
-- plain = true: точки и скобки — просто символы
card.Visible = query == "" or string.find(Lower(name), query, 1, true) ~= nil
-- конец перебора
end
-- конец функции
end)Где: StarterGui → ListGui · LocalScript
Зачем: Телепорты.
-- игроки
local Players = game:GetService("Players")
-- этот игрок
local player = Players.LocalPlayer
-- точки телепорта
local teleports = workspace:WaitForChild("Teleports")
-- ListGui
local gui = script.Parent
-- кнопка карты
local button = gui:WaitForChild("TeleportButton")
-- список мест
local frame = gui:WaitForChild("TeleportFrame")
-- прокрутка
local scrolling = frame:WaitForChild("ScrollingList")
-- шаблон
local sample = scrolling:WaitForChild("Sample")
-- кнопка
button.MouseButton1Click:Connect(function()
-- открыть / закрыть
frame.Visible = not frame.Visible
-- конец функции
end)
-- каждое место
for _, point in ipairs(teleports:GetChildren()) do
-- копия шаблона
local card = sample:Clone()
-- имя
card.Name = point.Name
-- подпись
card.LocationName.Text = point.Name
-- картинка места
local decal = point:FindFirstChildOfClass("Decal")
-- на кнопку
card.LocationImage.Image = decal and decal.Texture or ""
-- фон — цвет площадки
card.LocationImage.BackgroundColor3 = point.Color
-- показываем
card.Visible = true
-- в список
card.Parent = scrolling
-- клик по месту
card.LocationImage.MouseButton1Click:Connect(function()
-- персонаж
local character = player.Character
-- он есть
if character and character:FindFirstChild("HumanoidRootPart") then
-- переносим целиком над площадкой
character:PivotTo(point.CFrame + Vector3.new(0, 4, 0))
-- закрываем список
frame.Visible = false
-- конец проверки
end
-- конец функции
end)
-- конец перебора
endГде: StarterGui → GameOverGui · LocalScript
Зачем: Экран победы.
-- плавные появления
local TS = game:GetService("TweenService")
-- игроки
local Players = game:GetService("Players")
-- общее хранилище
local RS = game:GetService("ReplicatedStorage")
-- «нашёл всё»
local gameOverEvent = RS:WaitForChild("Events"):WaitForChild("GameOverEvent")
-- этот игрок
local player = Players.LocalPlayer
-- экран победы
local frame = script.Parent:WaitForChild("GameOverFrame")
-- «Поздравляем!»
local congrats = frame:WaitForChild("Congrats")
-- сколько найдено
local foundText = frame:WaitForChild("Found")
-- выйти
local exitButton = frame:WaitForChild("ExitButton")
-- играть дальше
local continueButton = frame:WaitForChild("ContinueButton")
-- полторы секунды, равномерно
local FADE = TweenInfo.new(1.5, Enum.EasingStyle.Linear)
-- плавно показать
local function Show(element)
-- виден (пока прозрачный)
element.Visible = true
-- проявляется
TS:Create(element, FADE, {BackgroundTransparency = 0, TextTransparency = 0}):Play()
-- конец функции
end
-- спрятать сразу
local function Hide(element)
-- не виден и не нажимается
element.Visible = false
-- прозрачный фон
element.BackgroundTransparency = 1
-- прозрачный текст
element.TextTransparency = 1
-- конец функции
end
-- кнопки подписываем один раз
exitButton.MouseButton1Click:Connect(function()
-- выход из игры
player:Kick("До встречи!")
-- конец функции
end)
-- играть дальше
continueButton.MouseButton1Click:Connect(function()
-- убираем экран
frame.Visible = false
-- конец функции
end)
-- сервер: найдено всё
gameOverEvent.OnClientEvent:Connect(function()
-- всё спрятано
for _, element in ipairs({congrats, foundText, exitButton, continueButton}) do Hide(element) end
-- текст
foundText.Text = "Ты нашёл все предметы: " .. #player.Found:GetChildren()
-- фон прозрачный
frame.BackgroundTransparency = 1
-- экран включён
frame.Visible = true
-- затемнение
TS:Create(frame, FADE, {BackgroundTransparency = 0.25}):Play()
-- ждём
task.wait(1.5)
-- поздравление
Show(congrats)
-- ждём
task.wait(1.5)
-- счёт
Show(foundText)
-- ждём
task.wait(1.5)
-- кнопки
Show(exitButton)
-- кнопки
Show(continueButton)
-- конец функции
end)Запусти Play (или Run) и убедись:
Roblox · Collect-a-thon · lesson 7
The whole course on one page: the full collect-a-thon structure and final versions of all scripts. Handy for checking your game or rebuilding it.
Blue — what we add in this lesson.
Workspace — StreamingEnabled off ├─ Map (Model) — zones ├─ Items (Folder) │ └─ предмет (Part) — Decal, Difficulty, Description, BadgeID └─ Teleports (Folder) — pads with a Decal ReplicatedStorage └─ Events (Folder) — CollectEvent, GameOverEvent ServerScriptService └─ CollectServer (Script) StarterGui — all ResetOnSpawn off ├─ CollectGui (ScreenGui) — Message, Found, CollectLocal ├─ ListGui (ScreenGui) — ListButton, ListFrame (Progress, SearchBox, ScrollingList → Sample), DescriptionFrame, TeleportButton, TeleportFrame, ListLocal, TeleportLocal └─ GameOverGui (ScreenGui) — GameOverFrame, GameOverLocal
Where: ServerScriptService · Script
Why: Finds, saving, game over.
-- players
local Players = game:GetService("Players")
-- shared storage
local RS = game:GetService("ReplicatedStorage")
-- saving
local DSS = game:GetService("DataStoreService")
-- badges (optional)
local BadgeService = game:GetService("BadgeService")
-- all items
local items = workspace:WaitForChild("Items")
-- events
local events = RS:WaitForChild("Events")
-- "found an item"
local collectEvent = events:WaitForChild("CollectEvent")
-- "found everything"
local gameOverEvent = events:WaitForChild("GameOverEvent")
-- the finds store
local store = DSS:GetDataStore("CollectData")
-- whose finds have loaded
local loaded = {}
-- save the finds
local function Save(player)
-- not loaded — don't overwrite
if not loaded[player] then return end
-- names of found items
local list = {}
-- each find
for _, mark in ipairs(player.Found:GetChildren()) do
-- into the list
table.insert(list, mark.Name)
-- end of loop
end
-- save
pcall(function() store:SetAsync("found_" .. player.UserId, list) end)
-- end of function
end
-- the player found an item
local function Collect(player, item)
-- their finds
local found = player:FindFirstChild("Found")
-- already found
if not found or found:FindFirstChild(item.Name) then return end
-- a marker
local mark = Instance.new("BoolValue")
-- name = item
mark.Name = item.Name
-- into the player's folder
mark.Parent = found
-- an on-screen message
collectEvent:FireClient(player, item.Name)
-- the badge ID
local badge = item:FindFirstChild("BadgeID")
-- the badge is set up
if badge and badge.Value > 0 then
-- don't hold up the rest
task.spawn(function()
-- award it; may not work in Studio
pcall(function() BadgeService:AwardBadge(player.UserId, badge.Value) end)
-- end of function
end)
-- end of check
end
-- everything is found
if #found:GetChildren() >= #items:GetChildren() then
-- in a second — the victory screen
task.delay(1, function() gameOverEvent:FireClient(player) end)
-- end of check
end
-- end of function
end
-- a player joined
local function Setup(player)
-- their finds
local found = Instance.new("Folder")
-- name
found.Name = "Found"
-- load it
local ok, list = pcall(function() return store:GetAsync("found_" .. player.UserId) end)
-- loading succeeded
if ok then
-- each saved name
for _, name in ipairs(list or {}) do
-- this item still exists
if items:FindFirstChild(name) then
-- a marker
local mark = Instance.new("BoolValue")
-- name
mark.Name = name
-- into the folder
mark.Parent = found
-- end of check
end
-- end of loop
end
-- saving is allowed
loaded[player] = true
-- end of check
end
-- into the player — the client sees it
found.Parent = player
-- end of function
end
-- new players
Players.PlayerAdded:Connect(Setup)
-- those who joined before the script ran
for _, player in ipairs(Players:GetPlayers()) do task.spawn(Setup, player) end
-- the player left
Players.PlayerRemoving:Connect(function(player)
-- save
Save(player)
-- forget
loaded[player] = nil
-- end of function
end)
-- the server is closing
game:BindToClose(function()
-- save everyone
for _, player in ipairs(Players:GetPlayers()) do Save(player) end
-- end of function
end)
-- each item — once
for _, item in ipairs(items:GetChildren()) do
-- a click
local clicker = item:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector")
-- you can only click from nearby
clicker.MaxActivationDistance = 20
-- into the item
clicker.Parent = item
-- someone clicked
clicker.MouseClick:Connect(function(player)
-- count it
Collect(player, item)
-- end of function
end)
-- end of loop
endWhere: StarterGui → CollectGui · LocalScript
Why: The find message.
-- shared storage
local RS = game:GetService("ReplicatedStorage")
-- "found an item"
local collectEvent = RS:WaitForChild("Events"):WaitForChild("CollectEvent")
-- CollectGui
local gui = script.Parent
-- a label
local message = gui:WaitForChild("Message")
-- the find sound
local sound = gui:WaitForChild("Found")
-- the number of the last message
local shown = 0
-- the server counted the find
collectEvent.OnClientEvent:Connect(function(name)
-- a new message
shown += 1
-- its number
local my = shown
-- text
message.Text = "Найдено: " .. name .. "!"
-- show it
message.Visible = true
-- a sound
sound:Play()
-- wait
task.wait(2.5)
-- hide it unless a new one arrived
if shown == my then message.Visible = false end
-- end of function
end)Where: StarterGui → ListGui · LocalScript
Why: Journal, description, search.
-- players
local Players = game:GetService("Players")
-- this player
local player = Players.LocalPlayer
-- all items
local items = workspace:WaitForChild("Items")
-- what the player has found
local found = player:WaitForChild("Found")
-- ListGui
local gui = script.Parent
-- the journal button
local listButton = gui:WaitForChild("ListButton")
-- the journal
local listFrame = gui:WaitForChild("ListFrame")
-- the scrolling list
local scrolling = listFrame:WaitForChild("ScrollingList")
-- the card template
local sample = scrolling:WaitForChild("Sample")
-- "Найдено: 2 / 6" (found 2 / 6)
local progress = listFrame:WaitForChild("Progress")
-- search
local searchBox = listFrame:WaitForChild("SearchBox")
-- the description window
local description = gui:WaitForChild("DescriptionFrame")
-- difficulty color
local COLORS = {Easy = Color3.fromRGB(80, 220, 100), Medium = Color3.fromRGB(255, 150, 40), Hard = Color3.fromRGB(240, 60, 60)}
-- easy ones first
local ORDER = {Easy = 1, Medium = 2, Hard = 3}
-- a found card
local FOUND_COLOR = Color3.fromRGB(150, 230, 120)
-- not found yet
local HIDDEN_COLOR = Color3.fromRGB(60, 60, 75)
-- item name → card
local cards = {}
-- recolor the cards and update the count
local function Refresh()
-- how many are found
local count = 0
-- each card
for name, card in pairs(cards) do
-- is the item found
local isFound = found:FindFirstChild(name) ~= nil
-- color
card.BackgroundColor3 = isFound and FOUND_COLOR or HIDDEN_COLOR
-- count
if isFound then count += 1 end
-- end of loop
end
-- the count
progress.Text = "Найдено: " .. count .. " / " .. #items:GetChildren()
-- end of function
end
-- lowercase letters, including Russian
local function Lower(text)
-- the result's letters
local out = {}
-- each letter by its code
for _, code in utf8.codes(text) do
-- А…Я
if code >= 1040 and code <= 1071 then
-- → а…я
code += 32
-- Ё
elseif code == 1025 then
-- → ё
code = 1105
-- end of check
end
-- into the result
table.insert(out, utf8.char(code))
-- end of loop
end
-- Latin — with the regular lower
return string.lower(table.concat(out))
-- end of function
end
-- the item description window
local function ShowDescription(item)
-- the StringValue with the description
local text = item:FindFirstChild("Description")
-- name
description.Title.Text = item.Name
-- the item is found
if found:FindFirstChild(item.Name) then
-- description
description.Body.Text = text and text.Value or ""
-- not yet
else
-- a riddle
description.Body.Text = "Найди этот предмет, чтобы прочитать о нём."
-- end of check
end
-- show it
description.Visible = true
-- end of function
end
-- a card for each item
for _, item in ipairs(items:GetChildren()) do
-- a copy of the template
local card = sample:Clone()
-- name
card.Name = item.Name
-- the caption
card.ItemName.Text = item.Name
-- the item picture
local decal = item:FindFirstChildOfClass("Decal")
-- onto the button
card.ItemImage.Image = decal and decal.Texture or ""
-- background — the item's color
if item:IsA("BasePart") then card.ItemImage.BackgroundColor3 = item.Color end
-- difficulty
local difficulty = item:FindFirstChild("Difficulty")
-- Easy if not set
local level = difficulty and difficulty.Value or "Easy"
-- the difficulty color strip
card.Difficulty.BackgroundColor3 = COLORS[level] or COLORS.Easy
-- order in the list
card.LayoutOrder = ORDER[level] or 1
-- the template was hidden
card.Visible = true
-- into the list
card.Parent = scrolling
-- remember
cards[item.Name] = card
-- click — description
card.ItemImage.MouseButton1Click:Connect(function() ShowDescription(item) end)
-- end of loop
end
-- found a new one — update
found.ChildAdded:Connect(Refresh)
-- right on joining
Refresh()
-- the journal button
listButton.MouseButton1Click:Connect(function()
-- open / close
listFrame.Visible = not listFrame.Visible
-- end of function
end)
-- close the description
description.CloseButton.MouseButton1Click:Connect(function()
-- hide
description.Visible = false
-- end of function
end)
-- text was typed into search
searchBox:GetPropertyChangedSignal("Text"):Connect(function()
-- what we search for
local query = Lower(searchBox.Text)
-- each card
for name, card in pairs(cards) do
-- plain = true: dots and brackets are just characters
card.Visible = query == "" or string.find(Lower(name), query, 1, true) ~= nil
-- end of loop
end
-- end of function
end)Where: StarterGui → ListGui · LocalScript
Why: Teleports.
-- players
local Players = game:GetService("Players")
-- this player
local player = Players.LocalPlayer
-- teleport points
local teleports = workspace:WaitForChild("Teleports")
-- ListGui
local gui = script.Parent
-- the map button
local button = gui:WaitForChild("TeleportButton")
-- the list of places
local frame = gui:WaitForChild("TeleportFrame")
-- scrolling
local scrolling = frame:WaitForChild("ScrollingList")
-- the template
local sample = scrolling:WaitForChild("Sample")
-- a button
button.MouseButton1Click:Connect(function()
-- open / close
frame.Visible = not frame.Visible
-- end of function
end)
-- each place
for _, point in ipairs(teleports:GetChildren()) do
-- a copy of the template
local card = sample:Clone()
-- name
card.Name = point.Name
-- the caption
card.LocationName.Text = point.Name
-- the place picture
local decal = point:FindFirstChildOfClass("Decal")
-- onto the button
card.LocationImage.Image = decal and decal.Texture or ""
-- background — the pad's color
card.LocationImage.BackgroundColor3 = point.Color
-- show it
card.Visible = true
-- into the list
card.Parent = scrolling
-- a click on a place
card.LocationImage.MouseButton1Click:Connect(function()
-- the character
local character = player.Character
-- it exists
if character and character:FindFirstChild("HumanoidRootPart") then
-- move the whole character above the pad
character:PivotTo(point.CFrame + Vector3.new(0, 4, 0))
-- close the list
frame.Visible = false
-- end of check
end
-- end of function
end)
-- end of loop
endWhere: StarterGui → GameOverGui · LocalScript
Why: The victory screen.
-- smooth fade-ins
local TS = game:GetService("TweenService")
-- players
local Players = game:GetService("Players")
-- shared storage
local RS = game:GetService("ReplicatedStorage")
-- "found everything"
local gameOverEvent = RS:WaitForChild("Events"):WaitForChild("GameOverEvent")
-- this player
local player = Players.LocalPlayer
-- the victory screen
local frame = script.Parent:WaitForChild("GameOverFrame")
-- "Поздравляем!" (congratulations)
local congrats = frame:WaitForChild("Congrats")
-- how many are found
local foundText = frame:WaitForChild("Found")
-- exit
local exitButton = frame:WaitForChild("ExitButton")
-- keep playing
local continueButton = frame:WaitForChild("ContinueButton")
-- one and a half seconds, evenly
local FADE = TweenInfo.new(1.5, Enum.EasingStyle.Linear)
-- fade in
local function Show(element)
-- visible (still transparent)
element.Visible = true
-- fades in
TS:Create(element, FADE, {BackgroundTransparency = 0, TextTransparency = 0}):Play()
-- end of function
end
-- hide at once
local function Hide(element)
-- invisible and not clickable
element.Visible = false
-- a transparent background
element.BackgroundTransparency = 1
-- transparent text
element.TextTransparency = 1
-- end of function
end
-- connect the buttons once
exitButton.MouseButton1Click:Connect(function()
-- leave the game
player:Kick("До встречи!")
-- end of function
end)
-- keep playing
continueButton.MouseButton1Click:Connect(function()
-- remove the screen
frame.Visible = false
-- end of function
end)
-- server: everything is found
gameOverEvent.OnClientEvent:Connect(function()
-- everything hidden
for _, element in ipairs({congrats, foundText, exitButton, continueButton}) do Hide(element) end
-- text
foundText.Text = "Ты нашёл все предметы: " .. #player.Found:GetChildren()
-- the background is transparent
frame.BackgroundTransparency = 1
-- the screen is on
frame.Visible = true
-- the fade
TS:Create(frame, FADE, {BackgroundTransparency = 0.25}):Play()
-- wait
task.wait(1.5)
-- the congratulations
Show(congrats)
-- wait
task.wait(1.5)
-- the count
Show(foundText)
-- wait
task.wait(1.5)
-- buttons
Show(exitButton)
-- buttons
Show(continueButton)
-- end of function
end)Press Play (or Run) and make sure: