Skip to content

Fix health metadata not saving on reconnect#1214

Open
AndyBodnar wants to merge 1 commit intoqbcore-framework:mainfrom
AndyBodnar:fix/health-metadata-save
Open

Fix health metadata not saving on reconnect#1214
AndyBodnar wants to merge 1 commit intoqbcore-framework:mainfrom
AndyBodnar:fix/health-metadata-save

Conversation

@AndyBodnar
Copy link
Copy Markdown

Summary

Fixes player health resetting to full on reconnect by properly saving and restoring health metadata.

Problem

When players disconnect and reconnect, their health resets to full instead of being preserved. This happens because:

  1. No health field existed in the default metadata
  2. Health was never captured from the client
  3. Health was never saved to the database
  4. Health was never restored on spawn

Solution

config.lua

  • Added health = 200 to default player metadata

client/loops.lua

  • Modified QBCore:UpdatePlayer to send current health and armor to server

server/events.lua

  • Modified QBCore:UpdatePlayer handler to save received health/armor to metadata
  • Modified playerDropped handler to capture health/armor before saving on disconnect

client/events.lua

  • Added health/armor restoration in OnPlayerLoaded event

Testing

Tested using LuaGround - all metadata persistence tests pass.

Related Issue

Fixes #1213

- Add `health` field to default player metadata (config.lua)
- Send health/armor from client to server in UpdatePlayer event (loops.lua)
- Save health/armor to metadata in QBCore:UpdatePlayer handler (events.lua)
- Capture health/armor on disconnect before save (events.lua)
- Restore saved health/armor on player load (client/events.lua)

This ensures player health persists across reconnects instead of
resetting to full.

Fixes qbcore-framework#1213
@06875878
Copy link
Copy Markdown

06875878 commented Mar 11, 2026

Does this also fix the issue of hunger and thirst metadata not saving on reconnect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] health metadata not update

2 participants