Server Exports
Server Exports
Section titled “Server Exports”All server exports can be called from other server-side resources using the exports function.
GetPlayerStats
Section titled “GetPlayerStats”Get the current cached stats for a player
local stats = exports['senor-topplayers']:GetPlayerStats(playerId)Parameters:
playerId(number) - The player’s server ID
Returns:
table | nil- Stats table, ornilif the player is not loaded
Stats Structure:
{ kills = number, deaths = number, damage = number, headshots = number, playtime = number, -- seconds money = number, vehicles = number, properties = number,}Example:
local stats = exports['senor-topplayers']:GetPlayerStats(source)if stats then print("Kills: " .. stats.kills)endAddPlayerStat
Section titled “AddPlayerStat”Add a numeric value to a player’s stat field. Updates in-memory cache only — persisted to DB when the player drops
local success = exports['senor-topplayers']:AddPlayerStat(playerId, field, value)Parameters:
playerId(number) - The player’s server IDfield(string) - Stat field to increment:'kills','deaths','damage','headshots','playtime','vehicles','properties'value(number) - Amount to add
Returns:
boolean-trueon success,falseif the player is not loaded or the field is invalid
Example:
exports['senor-topplayers']:AddPlayerStat(source, 'kills', 1)SetPlayerStat
Section titled “SetPlayerStat”Set a player’s stat field to a specific value. Updates in-memory cache only — persisted to DB when the player drops
local success = exports['senor-topplayers']:SetPlayerStat(playerId, field, value)Parameters:
playerId(number) - The player’s server IDfield(string) - Stat field to set:'kills','deaths','damage','headshots','playtime','vehicles','properties'value(number | nil) - Value to set, ornilto clear
Returns:
boolean-trueon success,falseif the player is not loaded or the field is invalid
Example:
exports['senor-topplayers']:SetPlayerStat(source, 'deaths', 0)SaveAllPlayerStats
Section titled “SaveAllPlayerStats”Force-persist all cached player stats to the database immediately
exports['senor-topplayers']:SaveAllPlayerStats()Example:
exports['senor-topplayers']:SaveAllPlayerStats()print("All stats saved.")