Multiplayer / How to update the score on each clients / How to make an AI following the closest player?

Hello everyone, I don’t know if I can ask 2 questions in one post but I’ll try.

So my game is a co-op game for 2-4 players which are fighting against AIs. I would like each time one of the players kill an AI the widget score updates for everyone.

My script in the playerState is working well for the server but not for the clients. I tried to cast to the gameMode to get my array of all players controllers & get the variable “NumberOfKills” from the player state for each of them in the widget but it’s not working.

I’ve tried many other random things to make it work but without any success.

I have a second question with AI : They only follows the server and I would like them to follow the closest player. But I don’t have any idea how to get a reference of others players since players are all index 0 in multiplayer.

Sorry for my bad english, thanks for reading.

Hi, might be more structured with two posts for two questions :slight_smile:

For the first question: The GameMode only exists only the server and not on the clients, so the clients can never access it since it does not exist there.
If it is working for the server and not for the clients, then it is a replication problem. You would need to replicate everything you want the clients to know about, you can do this directly in the player state and mark the relevant variables as “RepNotify”, so every time the server changes this variable it will execute a function on each client.


For the second question: “Get All Actors from Class” - playercontroller → for each loop → get controlled pawn → check distance to AI → choose closest


For more specific help you would need to show your code :slight_smile: