How to fix the value of a variable

I’m a little doubt, I think it is easy to solve, but I do not know … 

I’m needing to save the value of a scene to another, example: The player is playing, and the money variable increases, this value would stay for all scenes except for when I return to the menu, its value is getting null as if it did not exist …Will someone tell me how to set value for all my scenes?

to use variables in any scene you can make them global although i wouldn’t recomend it, instead create a new file called mydata.lua and write the following

local M = {} return M

then in all of your modules (eg main.lua) simply put

local myData = require( "mydata" )

then put 

myData.myVariable = 10

and it can be acessed throughout every module.

… i think

I’ve done most of the code, now only missing a few things, and they all wore

    Local M = {} ---- code     return M

but the variable I need to save it is in scene1.lua how will I do this?

no thats not quite what i mean have a look at this

Thaanks  *----* I managed to do

to use variables in any scene you can make them global although i wouldn’t recomend it, instead create a new file called mydata.lua and write the following

local M = {} return M

then in all of your modules (eg main.lua) simply put

local myData = require( "mydata" )

then put 

myData.myVariable = 10

and it can be acessed throughout every module.

… i think

I’ve done most of the code, now only missing a few things, and they all wore

    Local M = {} ---- code     return M

but the variable I need to save it is in scene1.lua how will I do this?

no thats not quite what i mean have a look at this

Thaanks  *----* I managed to do