Stellar AI

Errors

QBCore: Player is nil from QBCore.Functions.GetPlayer – Fix

The error

SCRIPT ERROR: @qb-myjob/server/main.lua:15: attempt to index a nil value (local 'Player')

What it means

QBCore.Functions.GetPlayer(src) returns nil when no character is loaded for that server ID. It happens when source is read too late (after a Wait or inside a callback), when the player is still on character select, has disconnected, or when the call is made from a client file.

The fix

local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('qb-myjob:server:reward', function()
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    if not Player then return end
    Player.Functions.AddMoney('cash', 100, 'myjob-reward')
end)

On the client, use QBCore.Functions.GetPlayerData() instead. Validate on the server that the player is actually allowed the reward (job, distance, cooldown) rather than trusting the event.

Related errors

Related tools: QBCore script generator · Fix a FiveM Lua error · all script generators