Setting attributes from ReplicatedFirst does not work if set too early

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)

attribute_nil.rbxl (44.5 KB)

5 Likes

Just sent this one to the team! We’ll update you as soon as we can.

1 Like

Hi @GnomeCode

Sorry for the delayed response.

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)

For more info on ReplicatedFirst, please find it here: ReplicatedFirst | Documentation - Roblox Creator Hub

If these suggestions don’t fit the needs, we’d like to understand further on your use case and offer other suggestions!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.