首先複製到所有客戶端的容器內容(但不會返回到伺服器),其他任何東西之前。
複製第一是為了什麼?
重複第一最常用於儲存LocalScripts和其他對遊戲啟動至關重要的物件。由於 ReplicatedFirst 的內容在遊戲中複製給客戶之前,其他任何東西之前,因此非常適合創建載入 GUI 或教學。
對於不需要先複製的對象,開發人員應該使用 ReplicatedStorage 容器進行替換。
我如何使用 ReplicatedFirst?
LocalScripts 放置在 ReplicatedFirst 內將運行。這意味著自訂載入屏幕或其他 ReplicatedFirst 使用的代碼可以在最早可能的時間點執行。
當在 ReplicatedFirst 執行 LocalScripts 時,開發人員需要記住的一些關鍵考慮因素。
- 其內容在遊戲中重複任何其他東西之前,意味著 LocalScripts 在 ReplicatedFirst 運行時需要等待任何需要重複使用 Instance:WaitForChild() 的對象
- 任何在 ReplicatedFirst 中使用的 LocalScript 對象也應該被傳送到 ReplicatedFirst。否則,它們可能會遲到客戶端複製,產生腳本並否認 ReplicatedFirst 的好處。
複製第一也包含功能 ReplicatedFirst:RemoveDefaultLoadingScreen() ,可用於立即移除預設 Roblox 載入頁面。注意如果任何對象被放置在 ReplicatedFirst,默認載入畫面將在 5 秒後移除,無論此功能是否已被呼叫。
範例程式碼
這個範例顯示了一個自訂載入屏幕,具有基本的 TextLabel 。代碼應放置在 LocalScript 內的 ReplicatedFirst 中。要擴展此樣本的載入屏幕動畫,請參閱 Custom Loading Screens 文章。
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- 創建基本載入屏幕
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)
textLabel.Font = Enum.Font.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- 將整個父畫面 GUI 轉換為玩家 GUI
screenGui.Parent = playerGui
-- 移除預設載入屏幕
ReplicatedFirst:RemoveDefaultLoadingScreen()
--等待(3) -- 可選擇強制屏幕在最少數秒內出現
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
概要
方法
立即移除預設 Roblox 載入屏幕。注意如果任何對象被放置在 ReplicatedFirst 中,默認載入屏幕將在 5 秒後移除,無論此功能是否已被呼叫。
屬性
方法
RemoveDefaultLoadingScreen
立即移除預設 Roblox 載入屏幕。注意如果任何對象被放置在 ReplicatedFirst 中,默認載入屏幕將在 5 秒後移除,無論此功能是否已被呼叫。
開發人員應該從 LocalScript 在 ReplicatedFirst 中執行此功能,因為在 ReplicatedFirst 中的腳本將在其他任何東西之前執行。
建議不要移除預設載入屏幕,除非開發者希望顯示自己的載入屏幕作為替代。如果預設畫面沒有被替換,使用者就能在背景中看到幾何載入。
返回
範例程式碼
這個範例顯示了一個自訂載入屏幕,具有基本的 TextLabel 。代碼應放置在 LocalScript 內的 ReplicatedFirst 中。要擴展此樣本的載入屏幕動畫,請參閱 Custom Loading Screens 文章。
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- 創建基本載入屏幕
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)
textLabel.Font = Enum.Font.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- 將整個父畫面 GUI 轉換為玩家 GUI
screenGui.Parent = playerGui
-- 移除預設載入屏幕
ReplicatedFirst:RemoveDefaultLoadingScreen()
--等待(3) -- 可選擇強制屏幕在最少數秒內出現
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()