# Adding 100 to a number every time a value increases by 1

I’m working on my Evolve money system and for every playtime hour you have, you get “100 stars” in your balance

I ran some maths on evolve’s code to get:
[lua]
timer.Create( “EV_MoneyCheck”, 60, 0, function()
for _, ply in ipairs( player.GetAll() ) do
Balance = ply:GetProperty( “Money” )
PlayTime = ply:GetProperty( “PlayTime” )
timer.Simple(2,function()
Hours = PlayTime / 60 / 60
Hours2 = math.Round(Hours)
Hours3 = Hours2 * 100
Money2 = Balance + Hours3
ply:SetProperty( “Money”, Money2 ) end)
end

``````evolve:CommitProperties()
``````

end )
[/lua]

That code above will not work, I know it wont but I am unsure how to fix it…

PlayTime in evolve’s standards is given in seconds so dividing by 60 twice give’s playtime in hours

Then I used a math.Round on the hours to give an increase of 1 everytime the hour goes up

Now I need to make it take ‘Balance’ and add 100 to it, everytime the playtime hour’s goes up

Hope that makes sense anyway…

Are you getting errors? And if so, what do they say? There’s also a few things you could do with improving:

-Lines 3-4, 6-9: Make the variables local.
-Only use ipairs if you want to sort through the table in order, pairs is faster.
-Timers count in seconds, so your delay should be 3600, not 60.

I normally try and fix the code before testing it, the code is incomplete you see…

And the timer is supposed to be 60 seconds, because everyone ranks up time’s at different times during that one hour.

I just need a function like e2’s changed(variable) function but I was unable to find one

Okay, try debugging certain parts of the loop, for example printing the Balance and PlayTime vars to check what they are being set to. I’ve put the code through a syntax checker and it found nothing, so it’s a game issue.

Okay found the problem

``````

Balance: 500
PlayTime: 407029.261
Hours: 113.06368361111
Hours 2: 113
Hours 3: 11300
Money 2: 11800

Balance: 11800
PlayTime: 407089.505
Hours: 113.08041805556
Hours 2: 113
Hours 3: 11300
Money 2: 23100

Balance: 23100
PlayTime: 407211.812
Hours: 113.11439222222
Hours 2: 113
Hours 3: 11300

``````

Each time it’s adding it back. I administered a function instead so it only runs once if the player’s “money” property doesn’t exist to add the players current time to it and then run once every minute to check if their playtime has increased by an hour, and add “50” to their money.