Any attribute set inside a localscript in the ReplicatedFirst container does not get properly applied if set immediately
I have created the following example with repo file
SetAttribute localscript (inside ReplicatedFirst)
workspace:SetAttribute("Test", true)
print("Set attribute to true from ReplicatedFirst at load")
task.wait(3)
workspace:SetAttribute("Test", true)
print("Set attribute to true from ReplicatedFirst after 3 seconds")
ReadAttribute localscript (located in StarterPlayerScripts)
while true do
print("Reading attribute", workspace:GetAttribute("Test"))
task.wait()
end
Result:
Set attribute to true from ReplicatedFirst at load
Reading attribute nil (x140)
Set attribute to true from ReplicatedFirst after 3 seconds
Reading attribute true (x109)
Yes, I can confirm what you’ve observed, and this is current expected behavior.
When using LocalScripts in ReplicatedFirst, we recommend only interacting with object that are parented to ReplicatedFirst.
This has to do with the timing of which localscripts within ReplicatedFirst is ran during join time. Because other instances outside of ReplicatedFirst (including Workspace from server) is replicated to the client after ReplicatedFirst is completed, the recommendation is to use an object within ReplicatedFirst to store this attribute if the attribute must be stored with this timing (when localscripts in ReplicatedFirst runs).
However, if you’d like to use an attribute in Workspace, for it to work, it needs to be set after game is loaded. It can be achieved by setting it during game load signal, eg:
game.Loaded:Connect(function()
workspace:SetAttribute("Test", true)
print("Set test attribute to true from ReplicatedFirst")
end)