플레이어의 인벤토리를 보유하는 컨테이너 개체.플레이어의 백팩에 있는 모든 Tool 는 화면 하단에 인벤토리에 표시됩니다.인벤토리에서 Tools 를 선택하면 Tool 이 장비되어 백팩에서 플레이어의 캐릭터로 이동합니다.
백팩은 플레이어의 백팩에 배치될 때 실행되는 Scripts 및 LocalScripts도 저장할 수 있습니다.
플레이어의 캐릭터가 생성되면 StarterPack의 콘텐츠와 StarterGear의 콘텐츠가 백팩에 복사됩니다.캐릭터가 한 번 죽으면 배낭이 제거되고 새로운 배낭이 생성되며 StarterPack 및 StarterGear의 콘텐츠로 채워집니다.
Roblox는 기본적으로 플레이어가 화면 하단에서 백팩과 인벤토리에 액세스할 수 있는 인터페이스를 제공합니다.개발자가 기본 Roblox 백팩 GUI를 비활성화하고 보유백팩 GUI로 교체하려는 경우 StarterGui:SetCoreGuiEnabled()를 사용하여 수행할 수 있습니다.
백팩은 클라이언트와 서버에서 모두 액세스할 수 있습니다.
local Players = game:GetService("Players")-- 서버 스크립트에서 백팩에 액세스:local backpack = Players.PlayerName.Backpack-- 로컬 스크립트에서 백팩에 액세스:local backpack = Players.LocalPlayer.Backpack
코드 샘플
This sample includes a simple function demonstrating how a Tool can be given to a Player by parenting it to their Backpack.
Backpack Give Tool
local Players = game:GetService("Players")
local function giveTool(player, tool)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
tool.Parent = backpack
end
end
local function onPlayerAdded(player)
local tool = Instance.new("Tool")
giveTool(player, tool)
end
Players.PlayerAdded:Connect(onPlayerAdded)