Spawning peds and earn money for kill them

Hello i try do make script where me spawns peds by button and earn money for killing them. Thanks for all anserws! I tried in several ways, but it didn’t work out for me

Now i make that but it didint work :frowning:

local playercoord = GetEntityCoords(ped)
local winnica = vector3(-1891.558, 2040.846, 140.0972)
local ped1 = “g_m_m_chicold_01”

Citizen.Wait(5000)

    if Vdist2(winnica , playercoord) <= 20 then

        TriggerEvent("FeedM:showNotification", "Ochroń cel przed atakującymi")

        newPed = CreatePed(4, ped1, -1891.588 , 2040.846, 142.0972, 0.0, false, true)

        SetPedCombatAttributes(newPed, 45, true)

        -GiveWeaponToPed(newPed, WEAPON_COMBATPISTOL), 2000, false, false)

        if GetEntityHealth(newPed) <= 20 then

            TriggerServerEvent('zlecenie:pieniadze', data)

        end

    else

       

    end

`local playercoord = GetEntityCoords(ped)
local winnica = vector3(-1891.558, 2040.846, 140.0972)
local ped1 = “g_m_m_chicold_01”

Citizen.Wait(5000)

if Vdist2(winnica , playercoord) <= 20 then

    TriggerEvent("FeedM:showNotification", "Ochroń cel przed atakującymi")

    newPed = CreatePed(4, ped1, -1891.588 , 2040.846, 142.0972, 0.0, false, true)

    SetPedCombatAttributes(newPed, 45, true)

    -GiveWeaponToPed(newPed, WEAPON_COMBATPISTOL), 2000, false, false)
    while GetEntityHealth(newPed) > 0 do 
      Citizen.Wait(100)
      if GetEntityHealth(newPed) <= 20 then

          TriggerServerEvent('zlecenie:pieniadze', data)

      end
    end

else

   

end`