Money In Game subtract certain variable if enough

Hey guys how do I make money in a game and when a button is touched if you money is greater then a certain variable then subtract the amount of the variable. My code below

tried making money! But failed :frowning:

_-----------------------------------------------------------------------------------------

– main.lua


– code below is acutally from local score = require(“score”)
local widget = require (“widget”)
print(numonscreen)
local money = 10000
local mypics = {“regularhouse.png”}

local rectangle = display.newRect(160,200,275,400)

local buy = widget.newButton
{
    left = -45,
    top = 350,
    id = “buybtn”,
    label = “Buy”,
    
}

local newcard = widget.newButton
{

    left = 160,
    top = 350,
    id = “newcardbtn”,
    label = “New Card”,

     

}

local onTouch
local someNewText
local centerX = display.contentCenterX
local centerY = display.contentCenterY

local text = display.newText(math.random(1000,10000),centerX,centerY,nil,40)
text:setFillColor(1,0,0)

function someNewText()
    text.text = math.random(1000,10000)
    transition.to(text, {time = 100, alpha = 1})
end
function onTouch(event)
    
    if (event.phase == “began”) then
                
                print(“it began”)
                transition.to(event.target,{time = 100, alpha = 0, onComplete = someNewText} )
        local r = math.random ( 1, #mypics )local item = display.newImage ( mypics[r], 150, 150 )
        local newcard1 = widget.newButton
        {
            left = 160,
            top = 350,
            id = “newcardbtn1”,
            label = “New Card”,
        }
    
       
        newcard1:addEventListener(“touch”,onTouch)
    end
end
    text:addEventListener(“touch”,onTouch)

      local moneydis = display.newText(money,50,50)
moneydis:setFillColor(1,0,0)

    function onTouch1(event)
        
        if (event.phase == “began”) then
                    
                    print(“it began”)
                
                    money = money - 100
       
        end
   
    end
   
    buy:addEventListener(“touch”,onTouch1)_

if (tonumber(money) > 99) then

   money = money - 100

else

   --inform the user that they don’t have enough money

end

The above code should work if implemented correctly. If not try putting money.txt as the tonumber

if (tonumber(money) > 99) then

   money = money - 100

else

   --inform the user that they don’t have enough money

end

The above code should work if implemented correctly. If not try putting money.txt as the tonumber