Checking for Closest Player?

I’m trying to code closest person checking into a few commands such as /cuff but I can’t seem to get it to work, this is what i’ve got so far:

local x, y, z = GetEntityCoords(GetPlayerPed(source))
for i = 1,32 do
        if i ~= source then
            local otherPlayer = GetPlayerPed(i)
            local mX, mY, mZ = GetEntityLocation(GetEntityCoords(otherPlayer))
            local distance = GetDistanceBetweenCoords(x, y, z, mX, mY, mZ)
            if distance <= 10 then
                CODE HERE

Does anybody know what I’m doing wrong? This is made with EssentialsMode in mind.

Is this one the server-side or client-side?

That particular code is Server Sided as i’ve merged it with commands that need it :slight_smile:

You can’t use natives on the server-side. They have to be executed by the client.

Okay, I’ll give that a go, thanks :wink: