Why is my money not being added?

I put a print text at the end and the text is NOT showing, so something is going wrong here:

theres not really a difference and I did change it and nothing got printed again, but thats not the problem, I dont think the code before it is working :confused:

It stops at the cast.

Try having it printed as a string instead of text

Its probably failing the cast, add a print string out of failed cast to see if it executes. (as a note i find it good practise to always put logs off failed casts with a message like “cast failed in FUNCTION NAME in CLASS NAME” this helps pick up these errors quickly instead of trawling through blueprint trying to find an error)

If it does then you’ll have to look whats causing the cast to fail, you do have a warning there so should point you in the right direction.

So myHUD is a widget you have created containing a variable called moneyvar?

What data type is the HUD ref variable?

That warning is only saying it is already myHUD so I dont need that cast to.

But yeah cast failed.

Do I need to set “myHUD” as the game settings HUD ? because my hud is the widget user interface but the hud settings is a hud class. Atm, the settings is on HUD class, is this the problem or is that how it should be ?

Yes myHUD is a user interface bp, It shows you your money and that is therefore where the money variable is.
The HUD ref goes to myHUD object reference.

If the HUD ref is a variable of the myHUD then you dont need the cast, make the variable public in the widget.

yeah ive already tried that, does nothing :frowning:

http://i.imgur.com/svsIO7O.png

Post a screenshot of where you’re setting the variable called “My HUD ref”

I created a variable in my AI soldier, the variable’s target is set to the HUD I made. When I kill the AI soldier, I want it to trigger an event where it gives me some money.

The money is shown in my HUD and this is where the money variable is.

This is the money variable function in my hud:

http://i.imgur.com/imO2iN0.png

Can you try adding a new bool that will be set to true when the actor is destroyed. Then set a branch on a tick event that if that new bool returns true to run the add money bit? You may want to run a DoOnce after the True part of the branch and before the set. I may be so off base here though. Sorry if I am.

still printing the string but not adding the 25 money :frowning:

##################################

Mistake was a placing code after “DestroyActor(Self)” block. “DestroyActor(Self)” block mark object like “Need to be deleted” and stop execute code next to destroy block.

You need to do all needed changes first, and delete self in the end

no that wasnt it, I need the store the money not in the hud widget, but if i store the variable in gamestate, each player will not have their own money hmmm

http://i.imgur.com/kA5iOqN.png

I had to do the adding in playerstate, not the widget lol.