Attach to vehicle does not work

local vehicle = CreateVehicle(Config.car.hash, -127.98, 1927.0, 197.09, 0.0, true, false)
local attach, baletrailer = GetVehicleTrailerVehicle(vehicle)

            if attach == true then
				SetNewWaypoint(0.0, 1815.29)
			end

i am trying to make this work but it wont. I would really appreciate it if someone could help me with this. I have been trying diffrent natives but it dosent work. I am trying to make it so when i attach the tractor2 to the baletrailer the new waypoint gets set.