Something that might be useful is being able to only sync a state bag to the local client, as there’s some data that might only be useful for the local client and doesn’t need to be sent to every other client.
This would be somewhat similar to how it’s currently done but add a 4th option that defaults to false
Player(1).state:set('someUniqueData', 'unique',
true --[[replicated]], true --[[ only sync to local client ]] )
Because this post is confusing as hell and the whole LocalPlayer for the individual client to update the Player state put my head through the ringer.
Client side:
-- This is client 1
-- Only on the 'local' client
-- example 1
LocalPlayer.state:set("This", data, false)
-- Client asks to sync the data
-- example 2
LocalPlayer.state:set("This", data, true)
-- This is client 500
-- from other clients to get "This" data.
Player(1).state.This
First example, unless declared on the server prior to change, would be nil as it doesn’t exist on the network.
Second example would return the player 1 data if called from another client.
This is what I have been rolling wih the understanding of.
--- bagName
--- value
--- replicated - server and all clients are aware of the value
client: LocalPlayer.state:set('this', data, true)
server: Player(6).state:set('this', data, true)
The idea being to add a fourth parameter which tells the statebag to only sync between the server and a specific client.
-- bagName
-- value
-- replicated - the value is synchronised with the server
-- private - other clients are not aware of this value (default: false)
Player(6).state:set('this', data, true, true)
playerId 6 is able to access LocalPlayer.state.this, but playerId 3 will return nil if attempting to view the value. Say we setup some resource for loading and storing player data (i.e. cfx-server-data playerdata) and want to attach some states to a player that other clients should not or do not need to be aware of.
You could of course just trigger a client event which will set this state with a non-replicated value when it’s modified by the server.
But doesn’t the server do this anyway if we are setting a client’s data?
The false flag is for replication to other clients, not inclusive of the client that the state represents?
EDIT:
No it doesn’t, I thought it would have, but a test provided nil.
Odd though, perhaps the false flag for replication can be changed to only send to the client it represents? Rather than adding a 4th parm?