Subtracting Coins - HELP NEEDED

Hey guys. Pretty new to UE4, but picking it up as fast as I can. So here is the issue.

I have created a coin system, the player moves over a coin and +1 (or +5 depending on the type of coin) is calculated on the HUD. The coin system works perfect.
What I need to happen now is when the player collides with a certain Blueprint Item then 60 coins need to subtract from the total value on the HUD.

Here is what I have so far.

When the game loads, the HUD is loaded via the level BP as shown.

In the ThirdPersonCharacter BP my AddScores function is like this:

In my HUD this is the Event Graph:

My HUD has a textblock on it that displays the collected scores (coins) this is the GetText:

Here is my Coin BP:

So up until this point everything works perfectly, player starts game, collects coins, coins are calculated on screen, great - but now I need to walk over a BluePrint item and have just that item subtract 60 coins from the HUD calculation. This is where I am stuck now.

Here is the BlueCandle Blueprint (when player walks over this the game should check if player has at least 60 coins, if so the item disappears and 60 coins subtracted, if player does not have 60 coins then the item stays there and nothing happens)

What I think I am supposed to do is create a Branch with the condition being if AddScores is greater or equal to 60 then TRUE if not then FALSE
When I try to drag off the <= condition and type AddScores or Scores nothing pops up.
I cannot figure out how to link this BluePrint to the AddScores function so I can subtract the coins from the HUD. I might be trying to do this the wrong way and after a week of tutorials and countless YouTUBE videos I am still at a loss here, I am hoping one of you professionals here has the easy solution for me.

Any and all detailed help is appreciated.
If you need any additional info or screenshots just let me know.

Many Many thanks in advance.

Subtracting the coins from the HUD is not the real problem as the coins on the HUD are linked to your characters coins.

Try cloning the Coin BP, change the value in Add Scores to -60, give it the Bluecandle mesh, try it.

On the fly I see that the “other actor” in the BlueCandle BP is not linked tho.

Hey dubstep_alex,

Looks like it could just be a simple fix and/or understanding to get this working. The <=] condition you have in the last image is for a “float” variable, and in the BP’s above it looks like the player score is an “Int”. So just recreate it by right clicking and typing “Int <=” into the blueprint search just to make sure you are referencing the correct variable type.

Also just to clarify, you will need to drag off the Cast to PlayerCharacter to have access to the function as it is in your Player Character class. Unless it is within a function library it might be called without the propper references.

Hope this helps!

If I just cloned the CoinBP and set AddScores to -60 then whenever the player moves over it, then it would always disappear with -60 taken away, right? There needs to be a check like I am trying to work out in the bottom picture (CONDITION, CHECK, IF: Does Player have 60 coins? YES, THEN - destroy item, subtract 60 coins. NO, ELSE - nothing happens.) This is what I am trying to work out in the CandleBP.

Your blue candle BP doesn’t look like it’s interacting with the player character at all. At the part where you cast to thirdpersoncharacter you could drag that pin off and store it as a player data reference (like you did with the HUD). You can then put that reference into the graph, drag a pin off of it and you should be able to find “scores”, which you can then use to check that it is >= 60.

If the check comes out true you can then drag a pin off the character reference and call the “AddScores” function, using -60 as the input and that should subtract 60 coins from your player.

OK so I went ahead and did what you said, cloned the COIN BP, set the AddScores to -60, went in game and as I predicted I collected 20 coins, picked up the candle and my HUD displays -40, pick up 5 more coins hud now says -35

So it kind of works, but there needs to be a check so the player never sees negative coins (-40), I think on this Candle BP I should drag off from the Branch node TRUE and do the subtract and destroy item then link it back to the Play Sound node, then drag off from the FALSE and add a Print Text node that prints “Not enough Coins” and where the current condition is set as == I should change it to <= - is this sounding about right to you guys?

I tried to follow everything you said exactly, does this look like what you were telling me to do?

After saving this and playing in game, when I try to collect the Blue Candle item, regardless of how many coins I have it always sends the Branch FALSE and displays “Not Enough Coins” even when I have 60 or more.

I have attached the Player Data var’s together as so:

Still the same problem, no matter how many coins I possess I cannot get the Candle.

I changed the Candle BP to this now to try and get it to work and still the same problem, no matter how many coins I have it seems the Branch node always goes FALSE.

When you cast to ThirdPersonCharacter, assign the result of that to Player Data straight away, then move on to the branch. My guess is you have the Player Data variable not actually referring to anything (so the scores value you’re pulling from it is probably just some default, likely 0).

Also make sure to hook up the execution pins in the true branch so that it goes to Add Scores, then moves on to destroy actor etc :slight_smile:

When I get back to my UE4 desk in a few hours i can do a mock-up of what I mean if we haven’t got it working by then :slight_smile:

Something like the below would work. Once you cast to third person character you should safe a reference to it, then you can actually read the scores value of the character. With that you can do your coin test and process accordingly.

THIS WORKS! I now have the ability to collect coins, calculate them on screen and the ability to purchase items with the subtraction working in AddScores! You guys are truly amazing!

Feel free to close this thread.