How to set it up so a client can request a new powerup from the server?

Yo! Let’s say I have two vehicles loaded into the game. One is the listen server, the other a client.

I have these functions for picking a random powerup from a list. However, I’m not sure how to get each vehicle to be picking a different powerup. I’m pretty sure this is just picking one random powerup and replicating it to every client, but I want every client to randomize their own power up when they need to.

They use the power up, ping the server that they consumed it, and then server eventually assigns them a new powerup. How should I be looking to implement this?

This is how I would look at it:

AMyPickupActor::AMyPickupActor( )
{
	BoxCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider");
	BoxCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyPickupActor::Overlap);
	SetRootComponent(BoxCollider);
	
	MyBuffClass = UMySuperBuffClass::StaticClass( );
	
	bReplicates = true;
}	

void AMyPickupActor::Overlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if(Role == ROLE_Authority)
	{
		AMyVehicleClass *Vehicle = Cast<AMyVehicleClass>(OtherActor);
		if(Vehicle)
		{
			Vehicle->GrantBuff(MyBuffClass);
		}
	}
	else
	{
		// Sound
		// FX
		// Other client side event(s) on overlap....
	}
}

// Vehicle

void AMyVehicleClass::GrantBuff(TSubclassOf<UMySuperBuffClass> InBuff)
{
	if(Role < ROLE_Authority)
	{
		Server_GrantBuff(InBuff);
	}
	else
	{
		// However you want to grant the buff, either to "this" vehicle
		// or, send a multicast out here for all "team" vehicles
		SendOutBuffs( );
	}
}

bool AMyVehicleClass::Server_GrantBuff_Validate(TSubclassOf<UMySuperBuffClass> InBuff)
{
	return true;
}

void AMyVehicleClass::Server_GrantBuff_Implementation(TSubclassOf<UMySuperBuffClass> InBuff)
{
	GrantBuff(InBuff);
}

You would create a Actor “Pickup” class, that is replicated. This class would have a collider component with a overlap function bound. When a vehicle overlapped it, i would then tell the vehicle to handle the buff (because all clients will have a copy of the vehicle class as I am guessing its from APawn). From there, I would check if its the server calling it - which is 100% will be as setup but if you had another call from the client, this would handle that too.

If it isn’t the server, it forwards the “buff” class in as a server function, which then goes back around to the GrandBuff, but this time as authority, and then can handle the event from the server side.