CreateWidget() returning nullptr

In code below im trying to create Widget and add it to ScrollBox. Problem is, I can’t because Item is nullptr. What have I done wrong?

void UInventoryWidget::InventoryInitalize(UInventoryComponent* InventoryLocal)
    {
    	InventoryBox->ClearChildren();

    	for (const UUItem* ItemHere : InventoryLocal->Items)
    	{
    		UInventoryItem* Item = CreateWidget<UInventoryItem>(GetWorld(), InventoryItemClass);
    		if (IsValid(Item))
    		{
    			InventoryBox->AddChild(Item);
    		}
    		else
    		{
    			UE_LOG(LogTemp, Warning, TEXT("Null"));
    		}
    	}
    }

What type is InventoryItemClass? TSubclassOf<UInventoryItem> ?
Also make sure that your widget code only runs on the client side.

  1. TSubclassOf<class UUserWidget> InventoryItemClass;

2.You mean this?
if(IsLocallyControlled())