State bags "LocalPlayer.state" stopped working (canary)

Client

  • canary

FXServer version

  • 4960
  • 5053
  • 5066
  1. What you expected to happen
    State bags should retain the information given to them.

  2. What actually happens
    State bags no longer can be set.

  3. Category of bug

  • Client
  1. Reproducible steps, preferably with example script(s)
  • Use canary for the client version (tested on 10/12/2021)
  • Connect to server
  • Login
  • Have the script trigger the event 'QBCore:Client:OnPlayerLoaded'
  • Have the script set 'LocalPlayer.state:set('isLoggedIn', true, false)'
  • Print 'LocalPlayer.state.isLoggedIn'
  • Results are 'nil'
TriggerEvent('QBCore:Client:OnPlayerLoaded')

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    ShutdownLoadingScreenNui()
    LocalPlayer.state:set('isLoggedIn', true, false)
    print(LocalPlayer.state.isLoggedIn)
    SetCanAttackFriendly(PlayerPedId(), true, false)
    NetworkSetFriendlyFireOption(true)
end)
  1. Test results on ‘Release’
  • Use release for the client version (tested on 10/12/2021)
  • Connect to server
  • Login
  • Have the script trigger the event 'QBCore:Client:OnPlayerLoaded'
  • Have the script set 'LocalPlayer.state:set('isLoggedIn', true, false)'
  • Print 'LocalPlayer.state.isLoggedIn'
  • Results are 'true'
1 Like

Resolved

How did you ‘resolve’ it?

It’s odd how two separate people have been ‘reporting’ this lately and each time it isn’t reproducible:

Honestly, I thought the canary version got updated overnight and that was it.

It’s the first time I have encountered the issue so I don’t have any more information, If I find another way this is triggered I’ll add on to the post.

1 Like

I’m now getting the exact same issue from time to time for unknown reasons, and at random restarts it will start working without me changing any config.

I’m running the exact code as OP and I’ve tested on several versions without luck.

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    LocalPlayer.state:set('isLoggedIn', true, false)
end)

Does anyone have a possible fix for this?

Do you have a repro for this, finally?

From the other topic:

Issue seems to be related to rejoining a server after getting disconnected.


In the current setup, there is no state being set on the player by the server.
The client uses non-replicated statebags LocalPlayer.state:set(k, v, false).
I closed FXServer while connected to the server.
I started FXServer and rejoined without restarting the client.
Any attempts to set states on LocalPlayer failed.

Setting any state on the player from the server allowed the client to set states again.

1 Like