Player Score and Server Score?

Okay so I posted this over in networking but I fixed my spawning issue and now I have one last issue that I am having a hard time getting my head around.

I need 2 separate scores and the current way it is set up is that a trigger box stores the scores of what people put into it so that’s the server score. Then everyone has their own personal score for each coin they toss into the trigger box. At the end of a round if the server score is above 4 each players personal score is multiplied by 1.6.

So I know how it should work, but the problem right now is I can’t communicate between the two scripts properly. I thought maybe doing a Master Script where both took from it would also update the values in it, but that’s not working so I need to find another way around this. So if anyone has any suggestions or solutions it would be a big help :slight_smile:

Right now the way it looks is pretty much

PlayerScore <==> MasterScript <==> ServerScore

If the PlayerScore script is written in the same language as the ServerScore script you just access information from that script via code:

// The reason why we dont use the "direct" refrence is because you want to grab the script
// of the player gameobject at runtime while it's being modified.
GameObject go_Player = GameObject.Find("player_gameobj_name");
PlayerScore ps = (PlayerScore) go_Player.GetComponent(typeof(PlayerScore));
// You can access the variable directly or use a get function.
ps.getCurrentCoinScore();

Adapted from this Unity answer.

With this you can just compare the scores to the ServerScore and just update the PlayerScore or whatever you need to update the sameway.

if (ps.getCurrentCoinScore() > 4) {
// Or whatever number you specifiy
// Do a thing.
}

Hopefully this helped.