How do global player variables work compared with PAWN? (SAMP)

Example for PAWN - SAMP

#define MAX_PLAYERS 501
PlayerJob[MAX_PLAYERS];


OnPlayerConnect(playerid)
PlayerJob[playerid] = 1; //Job 1 = Police.

OnPlayerEnterVehicle
if(VehicleFaction[vehicleid] != 1)return "You must be a police officer to drive this vehicle.")

LUA

Could someone explain how it works in LUA with saving global variables and passing these between clients?

Do I need functions on each client.lua?

Could someone kindly explain, I’d appreciate it.

Natives can be globally used: Native Reference - Cfx.re Docs

things like PlayerJob[MAX_PLAYERS] sadly doesn’t work here, as player ids are sort-of unique. (If you join the server with ID 1 and leave, the server won’t see ID 1 until you restart it)

Do I need functions on each client.lua

Not if you don’t make them local, BUT the functions are resource-bound. If you have a notification function, you will need that notification function in each resource.

Could someone explain how it works in LUA with saving global variables and passing these between clients?

I would suggest having a “core” resource that saves the player info, and use events to send that data to other resources.
Here’s a gamemode that I wrote a while back, that showcases how I handle data: GitHub - CritteRo/FiveDivision: A FiveM gamemode inspired by Tom Clancy's The Division

I made my data based on the way I used to code in SAMP, but adapted to FiveM ID structure.

Thank you for your kind reply.

I was trying to do this, via means of PlayerLoading

When you say events to send that data?

How would I do this:

    local playerid = source
    local adminlevel = exports.PlayerLoading:GetPlayerAdminLevel(playerId)


    TriggerClientEvent('chat:addMessage', playerid, {
        args = { 'print 1' }
    })
    print('print 1')

    if adminlevel < 1 then
        TriggerClientEvent('chat:addMessage', playerid, {
            args = { 'You are not authorized to use this command.' }
        })
        return
    end

At present I am loading the admin level with PlayerLoading:

    local pData = {
        PlayerName = name,
        AdminLevel = 0,
        Job = 0, -- Set the initial admin level to 0 (non-admin)
        -- Add more player data parameters as needed
    }

    if name == "Grant" then
        pData.AdminLevel = 1
    end

    PlayerData[playerid] = pData -- Store the player data in the global table

    print('Admin Level: ' .. PlayerData[playerid].AdminLevel)

This is causing great issue, passing between resources.

Thanks again for any further help.