Players (玩家)

Players 是一個跟蹤遊戲中所有當前玩家的服務。

它管理玩家資料,並提供處理玩家相關事件的功能,例如當玩家加入或離開遊戲時。

Image 1
Roblox Studio
local Players = game:GetService("Players")

local function printAllPlayers()
    for _, player in pairs(Players:GetPlayers()) do
        print("Player Name: " .. player.Name)
    end
end

printAllPlayers()
local Players = game:GetService("Players")

local function onPlayerAdded(player)
    print(player.Name .. " has joined the game.")
end

local function onPlayerRemoving(player)
    print(player.Name .. " has left the game.")
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)
Backpack儲存玩家在庫存中的工具和物品。這些可以透過 StarterPack 或動態地透過腳本加入。
PlayerGui包含玩家的使用者介面(UI)元素。該資料夾包含從 StarterGui 複製的 UI 元素的副本。
PlayerScripts儲存於客戶端為玩家執行的腳本。從 StarterPlayerScripts 複製的腳本會被放置在此處。