Ep 58. Replicated Storage Wait for Child
We created the Intro gui inside of the Replicated First service during this episode.
Unfortunately, a mistake was made which would cause an extremely rare issue. It took me over 3 months since publishing this episode to even encounter it.
The issue occurs because the
local script requires the ReplicatedFirst/Intro
ReplicatedStorage/Client/State
module script, which has a variable for the
folder. Scripts executed from the Replicated First service can rarely be executed before all of the children from the Replicated Storage service are replicated.ReplicatedStorage
/Remotes
We need to use the WaitForChild function when accessing children inside of the Replicated Storage service since scripts inside of the Replicated First service are executed before the children are replicated.
Solution
Update the first few lines of your ReplicatedStorage/Client/State
module script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Template = require(ReplicatedStorage:WaitForChild("PlayerData"):WaitForChild("Template"))
local IsDataLoaded = false
local PlayerData: Template.PlayerData
local function LoadData()
...