Delete Trailer

Hi, I need to delete the trailer as soon as the player reaches the location, but I can’t. I can uncouple the trailer, but it is no longer possible to delete it. Whats wrong?
0 errors

if IsVehicleAttachedToTrailer(GetVehiclePedIsIn(PlayerPedId())) == 1 then
  local trailer = GetVehicleTrailerVehicle(GetVehiclePedIsIn(PlayerPedId()))
  DetachVehicleFromTrailer(GetVehiclePedIsIn(PlayerPedId()))
  DeleteVehicle(trailer)
end

What do you get if you print trailer?

This function returns two values, likely ‘does it have a trailer’ and the actual trailer handle:

Corrected code:

local playerVehicle = GetVehiclePedIsIn(PlayerPedId())
local hasTrailer, trailer = GetVehicleTrailerVehicle(playerVehicle)

if hasTrailer then
  DetachVehicleFromTrailer(playerVehicle)
  DeleteVehicle(trailer)
end

TY! Perfect!