Roblox · Сбор-а-тон · урок 3

Журнал находок

Журнал со всеми предметами: картинка, название, цвет сложности. Найденные подсвечиваются, вверху счёт.

Структура

Синим — что добавляем на этом уроке.

StarterGui
└─ ListGui (ScreenGui) — ResetOnSpawn выкл.
   ├─ ListButton (TextButton) — «Журнал»
   ├─ ListFrame (Frame) — Visible выкл.
   │  ├─ Progress (TextLabel)
   │  └─ ScrollingList (ScrollingFrame) — AutomaticCanvasSize Y
   │     ├─ UIGridLayout (UIGridLayout) — CellSize 110 × 130
   │     ├─ UIPadding (UIPadding)
   │     └─ Sample (Frame) — шаблон, Visible выкл.
   │        ├─ ItemImage (ImageButton)
   │        ├─ ItemName (TextLabel)
   │        └─ Difficulty (Frame) — полоска сложности
   └─ ListLocal (LocalScript)

Шаги

  1. StarterGui → ScreenGui «ListGui» (ResetOnSpawn выкл.). Кнопка «ListButton» слева — открывает журнал.
  2. «ListFrame» (Visible выкл.): TextLabel «Progress» сверху, ниже ScrollingFrame «ScrollingList» (AutomaticCanvasSize = Y, CanvasSize = 0, 0, 0, 0 — прокрутка растёт сама).
  3. В ScrollingList — UIGridLayout (CellSize 110, 130 в пикселях, CellPadding 8) и UIPadding (8 со всех сторон).
  4. Шаблон «Sample» (Frame, Visible выкл.): ImageButton «ItemImage», TextLabel «ItemName», узкий Frame «Difficulty» — полоска цвета.
  5. LocalScript «ListLocal»: список строит сам игрок по папке Items — новые предметы появятся без правок интерфейса.
  6. LayoutOrder: лёгкие сверху, сложные внизу. Скрытые элементы UIGridLayout не учитывает — шаблон не занимает места.

Скрипты

ListLocal

Где: 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 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

-- карточка на каждый предмет
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
-- конец перебора
end

-- нашёл новый — обновляем
found.ChildAdded:Connect(Refresh)
-- сразу при входе
Refresh()
-- кнопка журнала
listButton.MouseButton1Click:Connect(function()
    -- открыть / закрыть
    listFrame.Visible = not listFrame.Visible
-- конец функции
end)

Проверка

Запусти Play (или Run) и убедись:

Roblox · Collect-a-thon · lesson 3

The finds journal

A journal of all items: picture, name, difficulty color. Found ones are highlighted and the count is at the top.

Structure

Blue — what we add in this lesson.

StarterGui
└─ ListGui (ScreenGui) — ResetOnSpawn off
   ├─ ListButton (TextButton) — "Журнал" (journal)
   ├─ ListFrame (Frame) — Visible off
   │  ├─ Progress (TextLabel)
   │  └─ ScrollingList (ScrollingFrame) — AutomaticCanvasSize Y
   │     ├─ UIGridLayout (UIGridLayout) — CellSize 110 × 130
   │     ├─ UIPadding (UIPadding)
   │     └─ Sample (Frame) — a template, Visible off
   │        ├─ ItemImage (ImageButton)
   │        ├─ ItemName (TextLabel)
   │        └─ Difficulty (Frame) — the difficulty strip
   └─ ListLocal (LocalScript)

Steps

  1. StarterGui → ScreenGui "ListGui" (ResetOnSpawn off). A button "ListButton" on the left opens the journal.
  2. "ListFrame" (Visible off): a TextLabel "Progress" on top, below it a ScrollingFrame "ScrollingList" (AutomaticCanvasSize = Y, CanvasSize = 0, 0, 0, 0 — the scroll area grows by itself).
  3. In ScrollingList put a UIGridLayout (CellSize 110, 130 in pixels, CellPadding 8) and a UIPadding (8 on all sides).
  4. A template "Sample" (Frame, Visible off): an ImageButton "ItemImage", a TextLabel "ItemName", a narrow Frame "Difficulty" — the color strip.
  5. LocalScript "ListLocal": the player's side builds the list from the Items folder — new items appear without editing the interface.
  6. LayoutOrder: easy at the top, hard at the bottom. UIGridLayout ignores hidden elements — the template takes no space.

Scripts

ListLocal

Where: StarterGui → ListGui · LocalScript
Why: The item journal.

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

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

Testing

Press Play (or Run) and make sure: