[HELP] Multiple Bugs while creating Panic Button

Hey I’m trying to make a Panic Button script but I have multiple bugs I dont know how to fix.

  1. When using the Script multiple times and reconnecting it then shows every Panic Button that was ever used
    image

  2. It wont delete the enabled blips after 5 minutes. I dont know how to fix it…

  3. I think every player sees the blips but I want it so only people with the police job see it.

ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local blips = {}
local function sendPanicMessage()
    local message = "Panic Button got pressed!"
    for _, player in ipairs(ESX.GetPlayers()) do
        local xPlayer = ESX.GetPlayerFromId(player)
        if xPlayer.job.name == "police" then
            TriggerClientEvent('okokNotify:Alert', player, 'Panic Button', message, 5000, 'panic', true)

            local playerPed = GetPlayerPed(player)
    local playerCoords = GetEntityCoords(playerPed)
    local blip = AddBlipForCoord(playerCoords)
            SetBlipSprite(blip, 41)
            table.insert(blips, blip)

SetTimeout(60000, function()
    print("Removing blip")
    for i, existingBlip in ipairs(blips) do
        if existingBlip == blip then
            table.remove(blips, i)
            RemoveBlip(blip)
            break
        end
    end
end)
        end
    end
end
RegisterCommand("panic", function(source, args)
    local xPlayer = ESX.GetPlayerFromId(source)
    local jobName = xPlayer.job.name
    if jobName == 'police' then
        sendPanicMessage()
    else
        TriggerClientEvent('esx:showNotification', source, "You cannot use this command.")
    end
end, false)

1.) Use a key,value table for the blips, then just call Wait(60000) instead of your entire SetTimeout function and remove the blips[blip]
blips[blip] = AddBlip(); SetSprite(); Wait(60000); RemoveBlip(); blips[blip] = nil;
2.) If you want it to delete after 5 minutes you need to Wait 60000*5
3.) You can not create the blip server side for only certain players to see it, you will need to move the blip creation client side. You’re simplest solution imo will be just handling the okokNotify:Alert event for the ‘Panic Button’ variable, and passing the position as an additional argument when you call it. This would be client side in your resource RegisterNetEvent('okokNotify:Alert', function(x, panicCheck, y, z, secondaryCheck, w, pos) if (panicCheck ~= "Panic Button") or (secondaryCheck ~= "panic") then return end blips[blip] = AddBlip(pos); SetSprite(); Wait(60000*5); RemoveBlip(); blips[blip] = nil end) and this would be the call from the server side TriggerClientEvent('okokNotify:Alert', player, 'Panic Button', message, 5000, 'panic', true, GetEntityCoords(GetPlayerPed(player)))