# How to transfer the last known value of a looping variable to other variable?

hello i have been making a 2d sidescroller game and stuck at a point where i need the total distance travel to show player their scores but i cant take the value to distance traveled because it is constantly looping and when player dies the value of other variable becomes zero.
The variables are shown in image:-

1. total distance traveled - The one who’s value is needed.
2. run - The one in which the distance value will be set.

I do not really understand what variables of yours have valid values and which don’t right now, but here is what I would do: Take the PlayerSpeed variable you have, and add it to the TotalDistanceTravelled * TimeDelta in your tick function. This should set the value of TotalDistanceTravelled correctly.

Sorry I don’t understand, I just want to know how to take the total distance travelled variable’s value and set its value into another variable to save it.

If you already have these variables, then all you need to do is to drag the variable wich you want to read from onto graph while holding CTRL. Then drag the variable which you want to write to onto the graph while holding ALT. You just need to drag the pin from the read variable - into the pin of the write variable.

You can see this on the graph that you posted: The very lower left node is a read node, and the node after “AddDistance” is a write node. Just plug the read node into the write node.

Can you please post a image of a blueprint to show distance travelled by player in HUD and also to save it somewhere. Please ,It will be a great help to me.

This graph will transfer the last known value of the variable “Distance Travelled” into the variable “Total Distance Travelled” each frame. I’m not sure what you want to see about the HUD.

I want to add 1 in distance travel every frame and when I dead condition is true then I want the last value of distance travel into other variable. What my unreal engine doing is that it add 1 in every tick but when I die it don’t give last value to other variable. I know my ques is little bit confusing but I can’t find find a way to explain better than this.

Hope these images will make you understand better

ok these screenshot indeed help. This is what you have to do:

Currently your Run variable is an array of floats. Make this to float only, no array, just like Total Distance Travelled.

In your

graph, set the Run variable like this:

In your

graph, you don’t need the “Get” node anymore. Connect the “Target Run” node to the “To Text (float)” Node directly.

That may be because your AddDistance event doesn’t get called if you die? You need to set the Run variable when you die before you change the TotalDistanceTravelled (i guess you reset this one if you die).

You could for example make a “OnDeath” event where you set the run variable.

I followed instructions but still getting 0 when dead, not the value of distance travelled saved in run.

Please can I get an image example it will be more easy for me understand from that.

Sorry, but this is not something one can explain with a few images. I would suggest your read up on the documentation. You also seem to lack some very basic knowledge about blueprints, so I would strongly suggest that you practice using blueprints in general, maybe with some tutorials online. I would like to close this question, because I don’t think that this discussion is going to lead to a solution.