Vehicle does not spawn

I am trying to make a function so when i press “Y” after the ShowAdvNotification a tractor2 spawns, but it does not seem to work.
Can someone help me? All help is appreciated

    ShowAdvNotification("CHAR_MP_ARMY_CONTACT", "Jonas", "Hö leverans", "Kan du hjälpa mig att leverera en vagn med hö? ~y~ Y/~r~N")
    Citizen.Wait(5000)

    if IsControlJustReleased(1, 246) then
      function SpawnVehicle(request)
        local myPed = GetPlayerPed(-1)
        local player = PlayerId()
        local vehicle = GetHashKey(request)
      
          RequestModel(vehicle)
      
        while not HasModelLoaded(vehicle) do
          Wait(1)
        end
      
        local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
        local spawned_car = CreateVehicle(vehicle, coords, 64.55118,116.613,78.69622, true, false)
        SetVehicleOnGroundProperly(spawned_car)
        SetPedIntoVehicle(myPed, spawned_car, - 1)
        SetModelAsNoLongerNeeded(vehicle)
        if IsVehicleModel(spawned_car, GetHashKey("tractor2")) then
        end
      end
    end
  end

you simply defined a function without calling it.

  ShowAdvNotification("CHAR_MP_ARMY_CONTACT", "Jonas", "Hö leverans", "Kan du hjälpa mig att leverera en vagn med hö? ~y~ Y/~r~N")
    Citizen.Wait(5000)

    if IsControlJustReleased(1, 246) then
      SpawnVehicle('adder')
      function SpawnVehicle(request)
        local myPed = GetPlayerPed(-1)
        local player = PlayerId()
        local vehicle = GetHashKey(request)
      
          RequestModel(vehicle)
      
        while not HasModelLoaded(vehicle) do
          Wait(1)
        end
      
        local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
        local spawned_car = CreateVehicle(vehicle, coords, 64.55118,116.613,78.69622, true, false)
        SetVehicleOnGroundProperly(spawned_car)
        SetPedIntoVehicle(myPed, spawned_car, - 1)
        SetModelAsNoLongerNeeded(vehicle)
        if IsVehicleModel(spawned_car, GetHashKey("tractor2")) then
        end
      end
    end
  end

how do i call the function?
I tried the code u sent but nothing spawns still

you have the coords twice no?

coords params should be x,y,z and you pass coords AND 3 more

try local spawned_car = CreateVehicle(vehicle, coords, [heading], true, false)
or local spawned_car = CreateVehicle(vehicle, coords.x, coords.y, coords.z, [heading], true, false) not sure

[heading] should be a heading value

nothing seems to spawn anyway

i made it like this: local spawned_car = CreateVehicle(vehicle, -84.6, 1879.62, 197.29, 245.6, true, false)

i solved it: i wrote the function before Citizen.Createthread function:
function spawnCar()

RequestModel(Config.car.hash)
while not HasModelLoaded(Config.car.hash) do
	RequestModel(Config.car.hash)
	Citizen.Wait(0)
end

local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
local vehicle = CreateVehicle(Config.car.hash, -127.98, 1927.0, 197.09, 0.0, true, false)
SetEntityAsMissionEntity(vehicle, true, true)

end

and this after if IsControllPressed(0, 246)

spawnCar()
Citizen.Wait(10000)