一个容器,其内容首先复制到所有客户端(但不返回到服务器),然后才返回到服务器。
复制第一个用于什么?
复制第一个最常用于存储LocalScripts和其他对游戏开始动至关重要的对象。作为复制第一个复制到客户端之前游戏中的内容的一部分,它非常适合创建加载图形用户界面或教程。
对于不需要先进行复制的对象,开发人员应该使用 ReplicatedStorage 容器进行替换。
我如何使用 ReplicatedFirst?
LocalScripts 放置在 ReplicatedFirst 内将运奔跑。这意味着可以在最早可能的时间运行自定义加载屏幕或其他复制第一次使用的代码。
当在 ReplicatedFirst 运行 LocalScripts 时,开发人员需要记住的一些关键考虑因素。
- 其内容在游戏中复制之前,任何其他东西,意味着 LocalScripts 在 ReplicatedFirst 运行时需要等待使用 Instance:WaitForChild() 复制所需的任何对象
- 在 ReplicatedFirst 中使用的任何对象也应该被父辈到 ReplicatedFirst。否则,它们可能会迟到向客户端复制,产生脚本并否认 ReplicatedFirst 的好处。
复制第一个还包含函数 ReplicatedFirst:RemoveDefaultLoadingScreen() ,可用于立即删除默认 Roblox 加载屏幕。注意如果任何对象被放置在 ReplicatedFirst,默认加载屏幕将在 5 秒后移除,无论这个函数是否已调用。
代码示例
This sample demonstrates a custom loading screen with a basic TextLabel. The code should be placed in a LocalScript within ReplicatedFirst. To expand on this sample with loading screen animations, see the Custom Loading Screens article.
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Create a basic loading screen
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
-- Parent entire screen GUI to player GUI
screenGui.Parent = playerGui
-- Remove the default loading screen
ReplicatedFirst:RemoveDefaultLoadingScreen()
--wait(3) -- Optionally force screen to appear for a minimum number of seconds
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
概要
方法
立即移除默认 Roblox 加载屏幕。注意如果任何对象被放置在 ReplicatedFirst 中,默认加载屏幕将在 5 秒后移除,无论这个函数是否被调用。
属性
方法
RemoveDefaultLoadingScreen
立即移除默认 Roblox 加载屏幕。注意如果任何对象被放置在 ReplicatedFirst 中,默认加载屏幕将在 5 秒后移除,无论这个函数是否被调用。
开发人员应该从 LocalScript 在 ReplicatedFirst 中运行此函数,因为在 ReplicatedFirst 中的脚本将在其他任何东西之前执行。
建议不要移除默认加载屏幕,除非开发者希望显示自己的加载屏幕作为替代。如果默认屏幕没有替换用户将被移除,用户可以在背景中看到几何加载。
返回
代码示例
This sample demonstrates a custom loading screen with a basic TextLabel. The code should be placed in a LocalScript within ReplicatedFirst. To expand on this sample with loading screen animations, see the Custom Loading Screens article.
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Create a basic loading screen
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
-- Parent entire screen GUI to player GUI
screenGui.Parent = playerGui
-- Remove the default loading screen
ReplicatedFirst:RemoveDefaultLoadingScreen()
--wait(3) -- Optionally force screen to appear for a minimum number of seconds
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()