# Where should i store my money variable (so each player has their own)

**URL:** <https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248>\
**Category:** Community & Industry Discussion\
**Tags:** money, unreal-engine, question, Blueprint\
**Created:** [July 6, 2015, 1:59pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248 "2015-07-06T13:59:17Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 1:59pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/1 "2015-07-06T13:59:17Z")

</div>

okay so storing it on my hud widget doesnt work.

if i stored it on gamestate - everyone would share the money. I want everyone to have their own money…

so If i store it on the person’s character that would mean they can easily hack the money with cheat engine or something ?

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 2:04pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/2 "2015-07-06T14:04:56Z")

</div>

Make your own playerstate and store it there. It is automatically replicated and linked to the controller 🙂

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 2:13pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/3 "2015-07-06T14:13:43Z")

</div>

thank you but when I come to bind the money, i can not find “player state” … you know like before I can find “game state”

like my picture… i can find my playerstate but its not the same, what should go on the end there ?

[http://i.imgur.com/05535EJ.png](http://i.imgur.com/05535EJ.png)

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 2:18pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/4 "2015-07-06T14:18:09Z")

</div>

Did you create your own blueprint or c++ class extending the Playerstate? If yes you can set it as the default playerstate in the PlayerController blueprint (default param). I am not in front of the computer so I am not 100% sure of the place. It is either in the PlayerController or in the Game Mode.

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 2:21pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/5 "2015-07-06T14:21:18Z")

</div>

yes i have set my custom playerstate to be used as the game’s playerstate

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 2:22pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/6 "2015-07-06T14:22:39Z")

</div>

Good then get the PlayerController (like you do for the game state) and then from it get player state

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 2:33pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/7 "2015-07-06T14:33:20Z")

</div>

ah ofcourse, player controller attaches to player state it works 😃 thank u for confirming it to me 🙂

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 2:47pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/8 "2015-07-06T14:47:53Z")

</div>

okay problem, it is only changing on the server window, not the client, although it is set to replicate.

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 3:09pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/9 "2015-07-06T15:09:09Z")

</div>

If you modify it on the authority it should replicate correctly if you wet the variable to replicate.

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 4:29pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/10 "2015-07-06T16:29:21Z")

</div>

hi,

i tried this:

[http://i.imgur.com/F5MZCTe.png](http://i.imgur.com/F5MZCTe.png)

It changes nothing, if I set it to Remote only, it will keep increasing my money really fast without stopping!

If it is Auth only it changes nothing either.

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 4:35pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/11 "2015-07-06T16:35:15Z")

</div>

You walk on the money, the client gets the collision event then you call an event on the server only. The server checks the collision, updates the money and callback the client.

Is it what you do?

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 4:37pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/12 "2015-07-06T16:37:26Z")

</div>

I did that now, but now both client and server’s money goes up really fast without stopping ;o

oh lol i forgot to add kill actor but i put kill actor on now and its back to only the server going up normally ☹

soldier:

[http://i.imgur.com/fbPjpSA.png](http://i.imgur.com/fbPjpSA.png)

playerstate:

[http://i.imgur.com/pzeyARs.png](http://i.imgur.com/pzeyARs.png)

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 4:40pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/13 "2015-07-06T16:40:40Z")

</div>

On the client you should not update the money. In the event that runs on the server you update the money for the correct controller not the controller 0. You need a way to get the correct one (transfert or id).

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 4:46pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/14 "2015-07-06T16:46:33Z")

</div>

im sorry i dont understand, do you have an example ?

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 4:59pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/15 "2015-07-06T16:59:33Z")

</div>

Sure, for example I have “ready” variable in my playerstate.  
First the client clicks on the ready button :

 ![49270-2015-07-06+18_51_19-testcopymodel+-+unreal+editor.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/3/4635ceb1e5783edf568aa0d0f9cf768fa022fa65.png)

As you can see I am calling a controller event that will only be executed on the server and I give him my player ID.

Then the server will update the ready value as the client told him :

 ![49281-2015-07-06+18_52_34-testcopymodel+-+unreal+editor.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/3/3/433867c60a248b09156620baa698fa29a935ec7a.png)

Here you see that with my player ID I get the correct player state. It is not necessary to do it this way because the event is already on a controller and when you call it you need to give the right controller. I am doing this for other reasons.  
You can also see that I callback the client.

To finish on the client side I tell my game to update the graphics now. You can also use a replicatedusing in C++ to have a function called when it is updated.

 ![49282-2015-07-06+18_55_27-testcopymodel+-+unreal+editor.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/e/7ceca900ea33d5ba1e623f787b0ad045e359e753.png)

In brief it goes :

- Client X : _That_ just happened to me
- Server : _Checked, Updated_ You can update the visuals now client X (or All clients with a multicast)
- Client X : _Update itself_

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 5:15pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/16 "2015-07-06T17:15:55Z")

</div>

Could you tell me which pictures are from what.

Is it possible you could connect to my teamviewer 😛 ?

---

<div class="post-metadata">

**Author:** ![rXp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rXp](https://forums.unrealengine.com/u/rXp)\
**Post date:** [July 6, 2015, 5:18pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/17 "2015-07-06T17:18:28Z")

</div>

Sure, give me your email and I will email you back. ^^

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 5:24pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/18 "2015-07-06T17:24:43Z")

</div>

[dannyk90@hotmail.co.uk](mailto:dannyk90@hotmail.co.uk)

or if you have steam or skype that will be nice!

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 6:02pm UTC](https://forums.unrealengine.com/t/where-should-i-store-my-money-variable-so-each-player-has-their-own/324248/19 "2015-07-06T18:02:41Z")

</div>

thank you 😃
