Handle Map Entities Serverside

Is there a way to handle map entities from the server?

I’m currently working on a “Dumpster Diver” script/job.
My idea was to pass the entity (the trashcan) though the ‘TriggerServerEvent’ function.
The entity on serverside is always 0 no matter what, have tried the ‘NetworkGetNetworkIdFromEntity’ and ‘NetworkGetEntityFromNetworkId’ but still doesn’t work.
Is it even possible to use map entities like trashcans on the server?

CLIENT

-- [ CLIENT ] --
Citizen.CreateThread( function()
    Citizen.Wait( 10 )
    if findDumpster() and not isSearching then
        -- findDumpster() is my own function that returns dumpsterEnt if near an dumpster.
        ESX.ShowHelpNotification( "Tryk ~INPUT_CONTEXT~ for at gennemsøge skraldespanden", false, true, 5000 )

        if IsControlJustReleased( 0, 38 ) and IsPedOnFoot( PlayerPedId() ) then
            TriggerServerEvent( "dumpsterdiver:startSearch", dumpsterEnt ) -- dumpsterEnt is the dumpster im standing near.
        end
    end
end)

SERVER

-- [ SERVER ] --
RegisterServerEvent( "dumpsterdiver:startSearch" )
AddEventHandler( "dumpsterdiver:startSearch", function( dumpsterEnt )

    if DoesEntityExist( dumpsterEnt ) then

        print( "Dumpster entity exists" )

    end

end)

Make sure you pass the netId to the server, also to use such functions on the serverside make sure onesync is enabled.

Not sure I understand how…

From client to server

TriggerServerEvent( "dumpsterdiver:startSearch", NetworkGetNetworkIdFromEntity(dumpsterEntity) )
-- Even tried N_0x7242f8b741ce1086( entity ) instread.
-- The dumpsterEntity is set to a bin.

Server

RegisterServerEvent( "dumpsterdiver:startSearch" )
AddEventHandler( "dumpsterdiver:startSearch", function( dumpsterEntity )

    local ent = NetworkGetEntityFromNetworkId( dumpsterEntity )
    print( ent )

end

Still prints 0.

Edit: And one-sync is active
onesync_enabled true <-- in server.cfg

Make sure that you’re passing an entity id in NetworkGetNetworkIdFromEntity and not a model name, or hash.

How i find dumpsterEntity

function findDumpster()
    local playerPos = GetEntityCoords( PlayerPedId() )
    for key, var in pairs( Dumpsters ) do
        dumpsterEntity = GetClosestObjectOfType( playerPos, 2.0, GetHashKey(var), false, false, false )
        if DoesEntityExist( dumpsterEntity ) then return dumpsterEntity end
    end
    return nil
end

dumpsterEntity is what gets passed it returns a number if i print it.

test, that wasn’t very helpful.