Core
Player Data
Understand the RSG player object.
When a player loads in, RSG builds a player object containing all of their data and a set of helper functions. You retrieve it on the server with:
local Player = RSGCore.Functions.GetPlayer(source)The PlayerData table
Player.PlayerData holds everything about the character:
Player.PlayerData.citizenid -- unique, permanent character id
Player.PlayerData.source -- current session id
Player.PlayerData.name -- account name
Player.PlayerData.money -- { cash = 100, bloodmoney = 0 }
Player.PlayerData.charinfo -- firstname, lastname, birthdate, gender...
Player.PlayerData.job -- job name, grade, duty status
Player.PlayerData.metadata -- hunger, thirst, stress, and custom fieldscitizenid vs source
Use source for anything happening right now (it changes every session). Use
citizenid when you need to reference a character permanently, e.g. in a database.
Player functions
The object also exposes functions that safely mutate and persist data:
-- Money
Player.Functions.AddMoney('cash', 100, 'reason')
Player.Functions.RemoveMoney('cash', 25, 'reason')
Player.Functions.GetMoney('cash')
-- Jobs
Player.Functions.SetJob('sheriff', 2)
-- Metadata (needs, custom stats)
Player.Functions.SetMetaData('hunger', 100)
-- Persist to the database
Player.Functions.Save()Reading metadata
Needs such as hunger and thirst live in metadata:
local Player = RSGCore.Functions.GetPlayer(source)
local hunger = Player.PlayerData.metadata['hunger']
if hunger < 20 then
TriggerClientEvent('ox_lib:notify', source, {
description = 'You are starving!',
type = 'error',
})
endAlways validate on the server
Never trust values sent from the client. Fetch the player object on the server and check their real data before granting money, items or jobs.

