Permission check not working: attempt to call a nil value (global 'IsPlayerAceAllowed')

Hey! I coded a car spawning scipt for a server. Now I wanted to add a permission check so not everyone can spawn a car. Only the ones with the “easyadmin” permission should be allowed to. When I tested the script on my localhost server, it said: attempt to call a nil value (global ‘IsPlayerAceAllowed’). Of course Neither the car spawns or it shows the error message that i have no perms.
This is my client.lua:

RegisterCommand('car', function(source, args, rawCommand)



local car = args[1]
local player = PlayerPedId()
local x,y,z = table.unpack(GetOffsetFromEntityInWorldCoords(player, 0.0, 2.5, 0.5))
local playerHead = GetEntityHeading(player)


if IsPlayerAceAllowed(source, "easyadmin") then --permission check

    if car == nil then car = "adder" --default car (adder) when no car model is given
    end

        carhash = GetHashKey(car)
        RequestModel(carhash)
        
        Citizen.Wait(200)
        
        if not HasModelLoaded(carhash) then
            Notify("Fahrzeug konnte nicht geladen werden. Crash verhindert.") --Error message (Car couldn't load / wrong model name.)
            
        else

            local spawnedcar = CreateVehicle(carhash, x, y, z, playerHead)
            SetVehicleNumberPlateText(spawnedcar, "MoonLife") --car plate text
            SetVehicleCustomPrimaryColour(spawnedcar, 118, 32, 216) --car primary color (violette)
            SetVehicleCustomSecondaryColour(spawnedcar, 118, 32, 216) --car sec color (violette)
            SetVehicleNeonLightEnabled(spawnedcar, 0, true) 
            SetVehicleNeonLightEnabled(spawnedcar, 1, true)
            SetVehicleNeonLightEnabled(spawnedcar, 2, true)
            SetVehicleNeonLightEnabled(spawnedcar, 3, true)
            SetVehicleNeonLightsColour(spawnedcar, 118, 32, 216) --car neon color (violette)
            SetVehicleEngineOn(spawnedcar, true, true) --car spawns with turned on engine
            SetPedIntoVehicle(player, spawnedcar, -1) --player automatically drives the car after spawning it
            Notify(car)
            Notify("Erfolgreich gespawnt!") --notification text after spawning the car
     
        end

    else        

        Notify("Keine Rechte!") --Error Message (Player has o permissions!)
end

end)



function Notify(msg) --Notification settings (DO NOT CHANGE!)
        SetNotificationTextEntry("STRING")
        AddTextComponentSubstringPlayerName(msg)
        DrawNotification(false, false)
end

my fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'

author 'Tonay'
description 'Car Spawner'
version '1.0.0'

client_script 'client.lua'

Please help me with that thing… I really need it. Also I really wanna use the easyadmin ace-permission and not a new one.

To the best of my knowledge “IsPlayerAceAllowed” is a server native, you would have to send an event to the server and check it that way.

I think the better way to do it is make the command on the server side and create the entity on the server

How do I do that? can u give me a script example or smth pls? ^^

RegisterCommand("car", function(source, args)
    local car = args[0] or "adder"
    local ped = GetPlayerPed(source)
    local coords = GetEntityCoords(ped)
    local veh = Citizen.InvokeNative(GetHashKey("CREATE_AUTOMOBILE"),  GetHashKey(car), coords)
    TaskWarpPedIntoVehicle(GetPlayerPed(source), veh, -1) --<<--- Warp into driver seat
end, true) --<<--- Setting this to true means they need ace permission 'command.car'

This is assuming you’re using onesync as you should be, spawning entitiy on the server with CREATE_AUTOMOBILE means it’s a server owned entity so it shouldn’t despawn and it exists instantly so you don’t need to load the model or anything.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.