Backpack

顯示已棄用項目

*此內容很快就會推出您所選的語言版本。

A container object that holds a player's inventory. Any Tool in a player's Backpack will be displayed in their inventory at the bottom of their screen. Selecting Tools from the inventory will equip the Tool, moving it from the Backpack to the player's character.

The Backpack can also store Scripts and LocalScripts, which run when placed in a player's Backpack.

When a player's character spawns, the contents of the StarterPack and their StarterGear are copied into their Backpack. Once a character dies, the Backpack is removed and a new one will be created -- populating it with the contents of StarterPack and StarterGear.

Roblox provides an interface for a player to access their backpack and inventory by default at the bottom of the screen. If a developer wishes to disable the default Roblox backpack GUI and replace it with their own, they may do so using StarterGui:SetCoreGuiEnabled().

The Backpack can be accessed from both the client and the server.


-- Accessing Backpack from a Server Script:
game.Players.PlayerName.Backpack
-- Accessing Backpack from a LocalScript:
game.Players.LocalPlayer.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)

屬性

方法

活動