A StateBag is a server-side data store used in FiveM to maintain data and variables linked to player or server state. StateBags allow developers to persistently store information about a player's session or specific gameplay states without requiring constant communication between the server and client. They are typically used for inventory systems, vehicle states, or player progression and can store any server-related data that can then be queried or modified.
StateBags are stored on the server side but are accessible to both the server and client under proper synchronization.
Our server-side scripts use StateBags for two key features:
StateBags are used to manage vehicle fuel levels. The server maintains the current fuel state for each vehicle using a unique StateBag linked to the vehicle entity. This allows fuel levels to persist between interactions or server sessions.
Similarly, StateBags are utilized to track whether a vehicle's spotlight is active or not. This allows the spotlight's on/off state and direction to sync properly between server and client without requiring repeated checks or excessive communication.
StateBags have a rate limit by default in FiveM. This means that if too many updates are sent to the server in a short time, the server may throttle or reject these updates, leading to unexpected behavior. Examples include:
When these rate limits are exceeded, the server may either:
Understanding this behavior and implementing rate-limiting fixes is essential for stable server performance.
To address these problems, we can increase the rate limits. This ensures that StateBag updates (such as fuel or spotlight state changes) will have the resources required to update.
Here’s how you can fix this issue, in your server.cfg include the following:
set rateLimiter_stateBag_rate 2000
set rateLimiter_stateBag_burst 3000