腳本 (伺服器腳本)
Empty
Empty
Empty
Script 是一段僅在伺服器上運行的代碼(控制遊戲的主計算機)。
Empty
Empty
Empty
它處理重要任務,如管理遊戲規則、玩家資料以及需要保證安全和公平的操作。
Empty
Empty
Empty
遊戲狀態管理 (Game State Management) | 跟蹤玩家得分,確定遊戲獲勝者。 |
安全和驗證 (Security and Validation) | 驗證玩家是否有足夠的貨幣進行購買。 |
共享環境更改 (Shared Environment Changes) | 更新共享對象的位置。 |
網絡和通信 (Networking and Communication) | 執行需要伺服器驗證的操作或觸發所有客戶端的事件。 |
Empty
Empty
Empty
-- Script in ServerScriptService
-- Get the Players service
local Players = game:GetService("Players")
-- Function to run when a player joins
local function onPlayerAdded(player)
print("Welcome to the game, " .. player.Name .. "!")
end
-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)