Using MLAPI, how would I implement a score system per client?
I followed the setup tutorial for MLAPI and I got it to work with the connections. I can now join a game with multiple clients. I want to implement a score system.
Right now Ive made a singleton gameobject which holds a score value. At first I thought this score would be different for each client (which it isnt), so all clients are sharing the same score. Next I gave every player a score attribute. Now each player has its own score, but the issue is that whenever a player leaves the game, this score disappears.
I want each client to have a score which they can improve each game (like a money system). Where would I save this attribute to make this work.
PS: The player object gets destroyed after a game.
Answer by GetLitGames · Apr 29, 2021 at 07:53 AM
Using PlayFab API and storing a value in the users data is the best way. You can use the CustomID login, they have example code, and then set a key value pair of whatever name you want and save it. Read from that value at startup, each time after login. You can also serialize/deserialize your own class to json and store it since the key value pairs take strings, which is what most people do.
Thanks for your answer. Is this the only way? Isnt there a way to do this so the score gets stored locally on a players device without the need of a package? I Just need this to get a total score value which can be used outside of an online session.
Sure, you can use PlayerPrefs but you are building a multiplayer game and having logged in users is an important step (since the game already requires the internet). Having logged in users with actual user data is important. They can also change devices if they want to or play your game using multiple devices because you can switch them from CustomID (anonymous) to adding an email and password on their account later when you want.
Your answer
Follow this Question
Related Questions
Strange (Pun2) RPC Problem. (With Error message that doesn't appear in a google search at all) 1 Answer
Multiplayer First Person shooter similar to Battlefield 1 Answer
Multiplayer Hiding Layer just for Local Player 0 Answers
How do I add extra points for coming close to obstacle but NOT for coming close and colliding? 1 Answer