FIVEM MULTICHARACTER
SCRIPTING
Developing Custom Selection Systems
Author: Antigravity AI
Date: July 2026
Target: 2700 Characters
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
01 / Introduction & Contents
A multicharacter system is essential for any advanced FiveM roleplay server, letting players
create and manage multiple slots from a single interface. This step-by-step guide explains system
architecture, database tables, serverside fetching, client cameras, NUI setup, and security.
TABLE OF CONTENTS
01. Introduction & Contents Page 2
02. Concept & System Architecture Page 3
03. Database Schema Design Page 4
04. Server-Side Data Fetching Page 5
05. Client-Side UI Handlers Page 6
06. Designing the HTML & CSS Interface Page 7
07. NUI JavaScript Callback Integration Page 8
08. Spawning Peds & Routing Buckets Page 9
09. Performance Optimization & Anti-Exploits Page 10
© 2026 FiveM Scripting Guide Page 2 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
02 / Concept & System Architecture
When a player connects, the client-side starts a black screen, hides their character ped, and
triggers a server callback. The server fetches all saved characters for the player's license from the
database, then returns a JSON table. The client sends this to the NUI display.
DATA FLOW MATRIX
Step Trigger Logic Performed
Fades screen black, disables normal
1. Connection Player joins server
spawn.
2. Fetch Server Callback SQL Query returns list of characters.
3. Display NUI Focus Renders character selection UI.
4. Selection NUI callback post Loads data, deletes NUI, spawns ped.
© 2026 FiveM Scripting Guide Page 3 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
03 / Database Schema Design
Create a table named 'characters' in your MariaDB database. It should store character identifiers,
slot numbers, first names, last names, cash, bank, and skin data. Use a unique composite primary
key combining the player's license identifier and the character slot number.
SQL DDL SCHEMA EXAMPLE
CREATE TABLE characters (
identifier VARCHAR(50) NOT NULL,
slot INT NOT NULL,
firstname VARCHAR(50),
lastname VARCHAR(50),
cash INT DEFAULT 0,
bank INT DEFAULT 0,
skin LONGTEXT,
PRIMARY KEY (identifier, slot)
);
© 2026 FiveM Scripting Guide Page 4 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
04 / Server-Side Data Fetching
Register a server callback named 'multicharacter:getCharacters'. Use oxmysql to perform a
SELECT query matching the player's license. Once the query completes, serialize the table rows
into a structured JSON payload, then return it back to the client for UI rendering purposes.
LUA CALLBACK EXCERPT
-- Lua server callback structure
[Link]('multicharacter:getCharacters', function(source)
local license = GetPlayerIdentifier(source, 0)
local result = [Link]('SELECT * FROM characters WHERE identifier = ?',
{license})
return result
end)
© 2026 FiveM Scripting Guide Page 5 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
05 / Client-Side UI Handlers
Upon receiving the database payload, the client script sets NUI focus to true, showing the cursor
and displaying the selection panel. The script also spawns a temporary camera focused on a
scenic selection spot, ensuring the actual player character remains hidden from view.
CLIENT-SIDE CAM & NUI INITS
-- Focus NUI and configure camera
SetNuiFocus(true, true)
SendNUIMessage({action = 'show_ui', characters = data})
local cam = CreateCamWithParams('DEFAULT_SCRIPTED_CAMERA', 402.8,
-996.9, -99.0, 0.0, 0.0, 0.0, 50.0, false, 2)
SetCamActive(cam, true)
RenderScriptCams(true, false, 1, true, true)
© 2026 FiveM Scripting Guide Page 6 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
06 / Designing the HTML & CSS Interface
Build a modern UI container in HTML using CSS Grid. Use dark overlays, glowing borders, neon
purple drop shadows, and card elements for each character slot. Include a 'Create Character'
button for empty slots and a 'Select Character' action button for existing slot details.
NUI WEB DESIGN BLUEPRINT
HTML Structure:
<div class='container'>
<div class='slot' data-slot='1'>Slot 1</div>
<div class='slot' data-slot='2'>Slot 2</div>
<div class='slot' data-slot='3'>Slot 3</div>
</div>
CSS Styling Rules:
.container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.slot { background: rgba(22, 28, 44, 0.9); border: 2px solid #A855F7; box-shadow: 0 0
10px rgba(168, 85, 247, 0.5); }
© 2026 FiveM Scripting Guide Page 7 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
07 / NUI JavaScript Callback Integration
Write JavaScript event handlers to listen for clicks on character cards. When clicked, post the
selected slot and character ID back to the client-side Lua script using a fetch POST request. Add
smooth opacity transitions to fade out the interface when selection is confirmed.
NUI JS EVENT HANDLER
// JavaScript select character post request
function selectCharacter(slotId) {
fetch(`[Link] {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: [Link]({ slot: slotId })
}).then(resp => [Link]()).then(data => {
if([Link] === 'ok') [Link] = 'none';
});
}
© 2026 FiveM Scripting Guide Page 8 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
08 / Spawning Peds & Routing Buckets
After the NUI posts back, the client script deletes the UI overlay, fades out screen camera, and
requests the server to spawn the character. The server routes the player into an isolated routing
bucket during selection to prevent other players from interfering with the spawn.
ROUTING BUCKET FLOW
Routing and Dimension isolation:
1. Player triggers server selection callback.
2. Server assigns player to private routing bucket: SetPlayerRoutingBucket(source,
source).
3. Player loads model and coordinates: SetEntityCoords(...).
4. Once spawn is confirmed, server resets routing bucket back to default dimension 0.
© 2026 FiveM Scripting Guide Page 9 of 10
FIVEM SCRIPTING CUSTOM MULTICHARACTER SYSTEM
09 / Performance Optimization & Anti-Exploits
Ensure security by validating that the character belongs to the player's license on the server side.
Block rapid selection clicks by implementing a toggle cooldown, and ensure all temporary preview
peds are fully deleted to prevent resource memory leaks on the client side. xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SCRIPT SECURITY CHECKLIST
Optimization Rule Reason & Prevention
Prevent SQL injection or account hijacking by verifying
Validate ID Ownership
selected character matches player license.
Disable cards on click to prevent database double-writes
NUI Button Cooldown
from fast double-clicking.
Call DeleteEntity(ped) when destroying menu interface
Preview Ped Cleanup
to prevent ghost peds.
© 2026 FiveM Scripting Guide Page 10 of 10