Tiled Collision Problems Monogame-Extended

guys i am a monogame noob and i really need some help. My problem is with the monogame extended tilemaps using .tmx or tiled maps. My problems arent with the rendering which works perfectly. but with collisions.the code here

    foreach (var entityId in ActiveEntities)
    {
        var transform = _transformMapper.Get(entityId);
        var player = _playerMapper.Get(entityId);
        var speed = 50;
        var OldPos = transform.Position;
        var seconds = gameTime.GetElapsedSeconds();
        var movementDirection = PlayerFunctions.GetMovementDirection();
        transform.Position += speed * movementDirection * Time.deltaTime;
        ushort x = (ushort)(transform.Position.X/ tileWidth);
        ushort y = (ushort)(transform.Position.Y/ tileWidth);
        TiledMapTile? tile = null;
        layer.TryGetTile(x, y, out tile);
        //Console.WriteLine(tile.Value);
        if (tile.HasValue)
        {
            transform.Position = OldPos;
        }
    }

should work but. It doesnt seem to be working for my tilemap as it only detects some tiles and the code that i wrote here should theoretically work but it just locks me inplace as it thinks there is a tile in my place when there really shouldnt be.
also does anyone know about code tags on this forum.

people on discord already helped me resolve this you should use isblank instead of hasvalue.