Hi. I’m creating my own framework and I need help. I am trying to remove police AIs and vehicles from MRPD but the vehicles keep spawning back. Here is my code.

-- Clears cops
        local coords = GetEntityCoords(PlayerPedId())
        local coords2 = vector4(425.3635, -982.0348, 30.7101, 88.6179) -- coords to MRPD
        ClearAreaOfCops(coords2.x, coords2.y, coords2.z, 200, true)
        ClearAreaOfVehicles(coords2.x, coords2.y, coords2.z, 50, false, false, false, false, false)

You would probably be better off using the entityCreating event.

Example (this wasn’t tested or done in a proper editor so be weary):

local policeStations = {
    vector3(425.36, -982.03, 30.71),
}
AddEventHandler("entityCreating", function (entityHandle)
    local coords = GetEntityCoords(entityHandle)
    for i = 1, #policeStations do
        local station = policeStations[i]
        if #(station - coords) < 50.0 then
             -- canceling the event will cause the entity to not be created for other
             -- clients and be removed from the calling client, we return here to not
             -- keep doing the loop.
             return CancelEvent()
        end
    end
end)

Okay, another question and sorry for asking but no one is answering me, why can’t I call functions? IT doesn’t matter where it’s from, I get "attempted to call a nil value (field or method). I have referenced my scripts in shared but same error

It could be that you’re trying to call the function before it gets initialized. Scripts will get initialized in the exact order you declare in the [client/server]_scripts call.

Example:

client_scripts {
    "client/main.lua",
    "shared/util.lua",
}

If you try to use a function in citizen/main.lua but it requires a function from shared/util.lua you’re going to error because that script has not been interpreted yet, this should only happen right after the script has started though.

This can also happen if the function is declared as a local function which means it only exists in the local context of that file (so if the local function was declared in shared/util.lua, only shared/util.lua would be able to use it

Nope, I put all my shared scripts ABOVE the client and server both