[HELP] attempt to call a nil value (global 'DropPlayer') lua

Hi there
for some reason, it says DropPlayer is a nil value
but when I log it to the console its not nil

1

function kickPlayer()
    ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'kickPlayerId_menu', {
        title = 'Kick Player Id'
    }, function(data, menu)

        ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), "kickPlayerReason_menu", { 
            title = "Kick Player Reason"
        }, function(data2, menu2)

            id = data.value
            reason = data2.value or "You have been kicked."

            print(id .. " " .. reason)
            DropPlayer(id, reason)
        end, function(data2, menu2)
            menu2.close() 
        end)
        menu.close()
    end, function(data, menu)
        menu.close()
    end)
end

Can anyone point me in the right direction?

DropPlayer is a server side native, you’re trying to use it client side.

1 Like

And before you blindly write a server event with DropClient please add permission checks before this becomes the 500th exploitable resource

I tried adding this

for _, v in pairs(ESX.GetPlayers()) do
    local xPlayer = ESX.GetPlayerFromId(v)

    if xPlayer.getGroup() == "admin" then
        -- xPlayer.name is an admin!
    end
end

but I get this error
attempt to call a nil value (field ‘GetPlayers’)

Seems like you don’t have GetPlayers function in the ESX table. Do you have this at the top of your server script?

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

If you’re trying to check if the person that’s using this server event is an admin then skip the ESX.GetPlayers() part and just check it like this:

if ESX.GetPlayerFromId(source).group == 'admin' then

You will still need to make sure you’re getting the ESX object properly though, that seems like your issue since it’s not recognizing the GetPlayers() function.

Yes I have the ESX object
I used the ESX boilerplate

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

and this code is also nil

if ESX.GetPlayerFromId(source).group == 'admin' then

I think I might have messed something up

Is this part of the code in a server side file or are you still trying to use it in the client side?

Both the ESX.Players and ESX.GetPlayerFromId functions are server side only. The only thing you should have in your client side file is the menu, the permission check and the drop are both done by the server when the client menu asks to use it.

I was using the permissions check client-side
I don’t know why I thought that would work
anyway I put it in server-side and now it works
Thank you very much @anders

is there a way to let people with higher groups like super admin be able to use it without basically duplicating the code and changing the required group?