Okay, maybe try to do it the easiest way.
Do a white-listed steamid array where you declare you and your friends steamids (base64) in there to specify to the script to not kick them.
Add the following code without erasing anything from the previous code.
client.lua
-- rest of the script
local dontkick = { -- declare your steamids below
"steam:11000011aaaaaaa",
"steam:11000011bbbbbbb",
"steam:11000011ccccccc"
}
local whitelisted = nil -- and not false by default to detect if the script wait delay is not working
-- CODE --
local function checkIfWhitelisted(steamid)
for _, v in ipairs(dontkick) do -- looping through the dontkick array
if v == steamid then -- if match
print("You are now whitelisted")
return true -- a return will prevent from looping further since you've already got what you wanted
end
end -- if the loop ends = no match
print("Not whitelisted")
return false
end
RegisterNetEvent('afk:returnSteamID')
AddEventHandler('afk:returnSteamID', function(steamid) -- return steamid client side
whitelisted = checkIfWhitelisted(steamid)
end)
CreateThread(function()
TriggerServerEvent("afk:getSteamID")
if whitelisted == nil then
Wait(1000) -- important since events are asynchrone, under 1000ms, the script may continue before even getting the steamid
end
if not whitelisted then -- same as 'if whitelist == false then'
while true do
Wait(1000)
--rest of the script
end
end
end)
-- rest of the script
server.lua
RegisterServerEvent('afk:getSteamID')
AddEventHandler('afk:getSteamID', function() -- source = the current player
local steamid = GetPlayerIdentifiers(source)[1] -- 1 = the first element in the array which is the steamid
TriggerClientEvent('afk:returnSteamID', source, steamid) -- return the steamid to the client side
end)
-- rest of the script
You retrieve the steamid by calling the GetPlayerIdentifiers native which return an array with steamid, licence, xbl etc.
Since GetPlayerIdentifiers is a server side native, you’ll need a server event to call the GetPlayerIdentifiers, then a client event to get back the steamid from the server side.
Then you compare the retrieved steamid with the ones in the array, looping row by row.
Since steamids don’t change mid game, you may only need to run the script once when a player connects.
That’s why the verification code I wrote is before the infinite loop in the thread.
It checks whenever to run or not the afk resource for each player who connects.
This prevent the script from running in background for the whitelisted ones, since it’s doesn’t need to check if they’re afk anymore.
TL:DR if someone is whitelisted: the script end for that player immediately, otherwise it will run indefinitely for the other non-whitelisted players.