PiTyUs.Hire me

Engineering

KVP storage in FiveM: saving small data without a database

How FiveM resource KVP (key-value pairs) works: SetResourceKvp, GetResourceKvpString/Int/Float, deleting and iterating keys, client vs server storage, and when KVP beats a database — HUD positions, settings and flags.

Updated 9 min readBy PiTyUs · FiveM developer

Overview

Not everything belongs in MySQL. A player’s HUD layout, their preferred chat colour or whether they have seen the tutorial are tiny, personal values — and FiveM has a built-in key-value store for exactly that. It needs no database, no queries and no connection string.

The API

client.lua — remembering HUD settingslua
local function saveHud(settings)
    SetResourceKvp('hud_settings', json.encode(settings))
end

local function loadHud()
    local raw = GetResourceKvpString('hud_settings')
    return raw and json.decode(raw) or { scale = 1.0, showSpeed = true }
end

SetResourceKvpInt('tutorial_done', 1)
print(GetResourceKvpInt('tutorial_done')) -- 1

DeleteResourceKvp('hud_settings')
FunctionDoes
SetResourceKvp(key, string)Store a string
SetResourceKvpInt(key, int) / SetResourceKvpFloatStore a number
GetResourceKvpString/Int/Float(key)Read it (nil/0 if missing)
DeleteResourceKvp(key)Remove it
StartFindKvp(prefix)FindKvpEndFindKvpList keys starting with a prefix

Listing keys

Iterate all saved outfitslua
local handle = StartFindKvp('outfit_')
while true do
    local key = FindKvp(handle)
    if not key then break end
    print(key, GetResourceKvpString(key))
end
EndFindKvp(handle)

Client vs server KVP

Client KVPServer KVP
StoredOn the player’s PC, for your serverWith the server’s data
SurvivesAcross sessions on that PCAcross server restarts
Visible toThat player (and editable by them)Only the server
Good forUI settings, keybind hints, seen-tutorial flagsSmall server state, counters, simple flags

KVP or database?

Use KVP for…Use the database for…
Per-player UI preferencesAnything other players or staff must see
Small flags and countersMoney, items, vehicles, characters
Data only one resource needsData you query, join or report on

When the database is the right answer, see the oxmysql guide.

Frequently asked questions

What is KVP in FiveM?

A built-in key-value store scoped to each resource, available on the client and the server, for small values like settings and flags.

Where is client KVP stored?

On the player’s own PC, per server and per resource.

Can I store a table in KVP?

Encode it first: SetResourceKvp(key, json.encode(t)), then json.decode when reading.

Should I store money in KVP?

No. Client KVP can be edited by the player; valuable data belongs in the server’s database.

Need this built, not just explained?

Ten years of FiveM work, from Lua to NUI

Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.

Related guides