[Help] TriggerEvent not working properly (LUA)

Hello, I am using ActionMenu 1.0 and I have created a couple of functions that work properly but expect for this one.

RegisterNetEvent('Trunk')
AddEventHandler('Trunk', function()
	if IsPedInAnyVehicle(GetPlayerPed(-1), false) then
		if GetPedInVehicleSeat(GetVehiclePedIsUsing(GetPlayerPed(-1)), -1) then
			if IsVehicleDoorFullyOpen(GetVehiclePedIsUsing(GetPlayerPed(-1)), 5) then
				SetVehicleDoorShut(GetVehiclePedIsUsing(GetPlayerPed(-1)), 5, false)
				drawNotification('Shut')
				
			else
				SetVehicleDoorOpen(GetVehiclePedIsUsing(GetPlayerPed(-1)), 5, false, false)
				drawNotification('Open')
				
			end
		else
			drawNotification('Must be in driver seat')
		end
	else
		drawNotification('Must be in a vehicle')
	end	
end)

What I am trying to do is, to toggle the trunk of a vehicle using a NUI button, the problem is that the SetVehicleDoorShut is not working. I can only open the trunk and can’t close it, I have also noticed that if I switch the SetVehicleDoorShut with the SetVehicleDoorOpen makes the function only able to close the trunk and not open it.

When the trunk is open and the function gets triggered it opens the trunk again, showing the drawNotification.

Any help is much appreciated.¨
Thanks in advance,
G.H.0.S.T

Replace

if IsVehicleDoorFullyOpen(GetVehiclePedIsUsing(GetPlayerPed(-1)), 5) then

with

if GetVehicleDoorAngleRatio(GetVehiclePedIsIn(GetPlayerPed(-1), false), 5) > 0.0 then