I’m trying to make a fivem server script that runs off of qbcore what the script is supposed to do is if you speed in if the police catch you speeding they will pull you over and give you a fine kinda like gta5 pull me over mod but it spawns the police but it doesn’t spawn the police ped in the car driving around Los Santos heres my client script
local QBCore = exports['qb-core']:GetCoreObject()
local policePeds = {}
local function isPlayerSpeeding(playerPed, speedLimit)
local vehicle = GetVehiclePedIsIn(playerPed, false)
if vehicle ~= 0 then
local speed = GetEntitySpeed(vehicle) * 2.23694 -- Convert m/s to mph
return speed > speedLimit
end
return false
end
local function createPoliceBlip(vehicle)
local blip = AddBlipForEntity(vehicle)
SetBlipSprite(blip, 60)
SetBlipColour(blip, 38)
SetBlipFlashes(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Police")
EndTextCommandSetBlipName(blip)
return blip
end
local function spawnPoliceVehicle(model, coords)
local vehicleHash = GetHashKey(model)
RequestModel(vehicleHash)
while not HasModelLoaded(vehicleHash) do
Wait(1)
end
local vehicle = CreateVehicle(vehicleHash, coords.x, coords.y, coords.z, coords.heading, true, false)
SetVehicleDoorsLocked(vehicle, 1)
SetVehicleEngineOn(vehicle, true, true, false)
local pedHash = GetHashKey('s_m_y_cop_01')
RequestModel(pedHash)
while not HasModelLoaded(pedHash) do
Wait(1)
end
local ped = CreatePedInsideVehicle(vehicle, 4, pedHash, -1, true, false)
TaskVehicleDriveWander(ped, vehicle, 17.0, 786603) -- Police driving around
createPoliceBlip(vehicle)
SetPedAsCop(ped, true)
SetPedKeepTask(ped, true)
table.insert(policePeds, {ped = ped, vehicle = vehicle})
return vehicle, ped
end
CreateThread(function()
local policeModels = {"police", "police2", "police3"}
local spawnPoints = {
{x = 437.39, y = -981.15, z = 30.69, heading = 90.0},
{x = -1623.85, y = -881.35, z = 9.51, heading = 317.0},
{x = 1859.19, y = 3687.58, z = 34.27, heading = 30.0},
}
for _, point in ipairs(spawnPoints) do
local model = policeModels[math.random(#policeModels)]
local vehicle, ped = spawnPoliceVehicle(model, point)
print("Spawned police vehicle at: ", point.x, point.y, point.z)
end
local speedLimit = 45 -- Speed limit in mph
while true do
Wait(1000)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for _, policeData in ipairs(policePeds) do
local policePed = policeData.ped
local policeVehicle = policeData.vehicle
local distance = #(coords - GetEntityCoords(policePed))
if distance < 100.0 and isPlayerSpeeding(playerPed, speedLimit) then
TaskVehicleChase(policePed, playerPed)
SetDriveTaskCruiseSpeed(policePed, 35.0)
SetDriveTaskDrivingStyle(policePed, 786603)
while true do
Wait(0)
local policeCoords = GetEntityCoords(policePed)
local distanceToPlayer = #(policeCoords - coords)
if distanceToPlayer < 10.0 then
TaskLeaveVehicle(policePed, policeVehicle, 0)
TaskGoToEntity(policePed, playerPed, -1, 5.0, 2.0, 1073741824.0, 0)
Wait(3000) -- Delay for roleplay
TriggerServerEvent('police:deductMoney', 500)
TriggerEvent('QBCore:Notify', "You've been fined for speeding!")
break
elseif distanceToPlayer > 200.0 then
ClearPedTasks(policePed)
break
end
end
end
end
end
end)
and hers my server script
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('police:deductMoney', function(fineAmount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
Player.Functions.RemoveMoney('bank', fineAmount)
TriggerClientEvent('QBCore:Notify', src, 'You have been fined $' .. fineAmount, 'error')
end
end)