[Help] Script efficiency. Is there any easier way?

I’m currently working on a script and want to set up a hierarchy of current ‘managers’. I’ve got the below script that I’ve created.

Essentially, while a higher manager is on the server a lower ranking employee won’t be able to use the ‘managers’ features.

I’m sure there is a more efficient way to do this but can’t, for the life of me, think of how to achieve that. Any pointers would be greatly appreciated :slight_smile:

CONFIG.lua

--[[
####		These would be actual an actual identifier but have omitted for an obvious reason
]]--
MANAGER = "STEAM IDENTIFIER 1",
ASSISTANT_MANAGER = "STEAM IDENTIFIER 2",
TRUSTED_MEMBER = "STEAM IDENTIFIER 3",

Client.lua

local manager = false

AddEventHandler('playerSpawned', function()
    TriggerServerEvent("Server:Check")
end)

AddEventHandler("playerDropped", function()
	if manager then
    	TriggerServerEvent("Server:Reset")
    end
end)

RegisterNetEvent("Client:Set")
AddEventHandler("Client:Set", function(args)
    manager = args
end)

RegisterNetEvent("Client:Reset")
AddEventHandler("Client:Reset", function(args)
    TriggerServerEvent("Server:Check")
end)

Server.lua

local manager_check = false
local assistant_check = false
local trusted_check = false

RegisterNetEvent("Server:Reset")
AddEventHandler("Server:Reset", function(args)
	manager_check = false
	assistant_check = false
	trusted_check = false
    TriggerClientEvent("Client:Reset", -1)
end)

RegisterServerEvent("Server:Check")
AddEventHandler("Server:Check", function()
	local pid = table.unpack(GetPlayerIdentifiers(source, 1))
	if CONFIG.MANAGER == pid then
		manager_check = true
		TriggerClientEvent("Client:Set", -1, false)
		TriggerClientEvent("Client:Set", source, true)
	elseif CONFIG.ASSISTANT_MANAGER == pid and not(manager_check) then
		assistant_check = true
		TriggerClientEvent("Client:Set", -1, false)
		TriggerClientEvent("Client:Set", source, true)
	elseif CONFIG.TRUSTED_MEMBER == pid and not(manager_check) and not(assistant_check) then
		trusted_check = true
	    TriggerClientEvent("Client:Set", -1, false)
		TriggerClientEvent("Client:Set", source, true)
    end
end)```

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