Peds should attack players with vehicles, but it doesn't work?

This is my code:

Citizen.CreateThread(function()
while true do
if IsControlJustReleased(0, 166) then
spawnPed()
end
Citizen.Wait(1)
end
end)

function spawnPed()
local ped = “s_m_y_blackops_01”
local vehicle = “lazer”
local coords = GetEntityCoords(PlayerPedId())
local heading = GetEntityHeading(PlayerPedId())

RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
		Citizen.Wait(1)
end

RequestModel(ped)
while not HasModelLoaded(ped) do
		Citizen.Wait(1)
end

local spawnedPed = CreatePed(0, ped, coords.x, coords.y, coords.z, heading, true, false)
local spawnedVehicle = CreateVehicle(vehicle, coords.x, coords.y + 10, coords.z, heading, true, false)


SetPedIntoVehicle(spawnedPed, spawnedVehicle, -1)
TaskCombatPed(spawnedPed, PlayerPedId())
TaskShootAtEntity(spawnedPed, PlayerPedId(), -1, 0)
SetPedCombatAttributes(spawnedPed, 1, true)
SetPedCombatAttributes(spawnedPed, 3, false)
SetPedCombatAttributes(spawnedPed, 5, true)
SetPedCombatAttributes(spawnedPed, 13, true)
SetPedCombatRange(spawnedPed, 0)


SetModelAsNoLongerNeeded(ped)
SetModelAsNoLongerNeeded(vehicle)

end

Here a ped is spawned in a jet and it is then supposed to attack the player WITH THE JET (and the use weapons from the jet). But this doesn’t work the way it’s supposed to!

Here’s what happens: The jet spawns with the ped but it doesn’t do anything except scream a little.
When i shoot he flies off, but not to attack me, NO, but simply to fly into nowhere! BUT WHY???

In general it should be like this that when the jet spawns with the ped it should fly off and attack the player with the lazer jet weapons WITHOUT YOU FIRST SHOOTING → and the problem lies with every vehicle, not just with the lazer jet!

So my question now is which natives/functions do I have to use to solve the problem and how can I generally tell peds that if they attack me with a vehicle, they should take THE DAMN VEHICLE WEAPON and not get out and hit the player or just fly away?

  • sorry for my bad english btw

thank you!