Setting attribute to player in StarterPlayerScripts does not work

Reproduction Steps
When I set an attribute to my Player on StarterPlayer, it doesn’t appear on my player, and thus other local scripts aren’t able to do GetAttribute for it, causing my entire game to break

Repro.rbxl (32.0 KB)

Expected Behavior
The attribute I set should appear on my player

Actual Behavior
image
No attributes at all.

Workaround
No

Issue Area: Engine
Issue Type: Other
Impact: Very High
Frequency: Constantly

3 Likes

I have had this issue about a week or 2 ago, move it to StarterCharacterScripts.

Although it only broke for me when I reset my character but everything else in the script worked.

No can do. My character doesn’t auto load on start. I need these attributes set basically as soon as the player joins, as theres multiple scripts that require this information before the players character has loaded into the game

Is there a error at all that it’s giving or just nothing happens?

I actually see your issue, I ain’t sure if its thinking it’s getting changed on the server before you change the client. I tried 2 other ways to do what you wanted to do and it diddn’t work. You could try and do it on server but I ain’t sure why you need it on the client tho. If this helps if I need attributes I always put a folder in StarterGui and put attributes there but lots of people have different ways to use these.

Edit: It seems it only doesn’t work in StarterPlayerScripts because for me it works on StarterCharacterScripts. Try to use GetAttribute and stuff from StarterPlayerScripts script then edit this post it seems like attributes doesn’t work at all in StarterPlayerScripts

1 Like

I can’t do it on the server, as the stuff I am setting the attributes off is client side (basically setting what device they are on)

Read what I put on the Edit. It seems like there is more about this problem than just setting the attribute.

I mean either way, my bug report still stands. There’s no documentation stating that attributes shouldn’t be setable in StarterPlayerScripts, thus regardless of its right or wrong, this bug is still valid

The admins would like to know that ALL attributes doesn’t work not just Setting the Attribute. It will help with them to fix this.

This code should work as-is because LocalPlayer is implicit to LocalScripts and starter containers don’t copy until Loaded fires. That being said, I did some testing myself and it seems like this is a quirk of Immediate SignalBehaviour and how the player is created - you’re encountering a race condition.

If you’re using Default (Immediate) SignalBehaviour this code will resolve your issue:

local LocalPlayer = game:GetService("Players").LocalPlayer
task.defer(LocalPlayer.SetAttribute, LocalPlayer, "foobar", "foobar")

If you’re using Deferred SignalBehaviour then your original code will work without any changes needing to be made. I’d recommend deferring your attribute in the meantime so that it will set as soon as possible. Any code that requires the attribute should yield unless that code will predictably execute after the attribute has been set.

3 Likes

Can I ask what signalbehaviour is exactly?

See this thread:

This happens because the player object gets replicated twice for arcane legacy reasons. All the player properties set in that context will actually get blown away, not just the attributes.

This is something that should have been dealt with properly earlier, an engineer is looking into a solution though it’s not trivial because there may be some backwards compatibility concerns.

4 Likes

Hey! Sorry we took so long, but we just released a fix that no longer replicates the Player object twice. Please let us know if your experience is still …experiencing this issue!

6 Likes

Hey everyone!

I’m closing this thread per the above reply from our Roblox Staff!
We assume the issue was fixed that time due to no feedback from the developer!
Feel free to file another bug report if the issue is still occurring!

Thank you!