Frameworks & scripts

State bags

Also called statebags, GlobalState, entity state

FiveM's built-in key-value storage attached to entities, players or the whole server, automatically replicated between server and clients under OneSync.

State bags are key-value stores that FiveM replicates for you. There are three scopes:

  • GlobalState for server-wide values like weather or an event flag.
  • Player(serverId).state and LocalPlayer.state for values tied to a player.
  • Entity(entity).state for values tied to a networked entity such as a vehicle.

They require OneSync, because replication runs through the same system that tracks entities. Setting a value on the server sends it to every client that knows about that entity. Clients can also set values on entities they own, but only with replication turned on, and the server can reject or override them.

State bags replace a lot of older patterns. Instead of triggering events to every client whenever a vehicle's fuel or lock state changes, a script writes Entity(veh).state.fuel = 42 and every other script that needs it reads the same value. AddStateBagChangeHandler lets resources react to changes without polling.

They are not a database. Values exist only while the entity exists and the server is running, so anything that must survive a restart still belongs in MariaDB through oxmysql.

Security matters too. Never trust a state bag value that a client could have written for anything that affects money or permissions. Server-written values are authoritative; client-writable ones are inputs to be validated, the same as event arguments. With entity lockdown and careful use of replication flags, state bags become one of the cleaner tools in the platform.

Related terms

Trying to get your server seen?

The live leaderboard shows what the numbers look like at the top of the list, and the upvote calculator turns a target server into a campaign size. The full glossary is here.