What's wrong with this?

Can someone find what’s wrong with this code? It is to add 5$ every 5 seconds to the hud code:

[lua]if SERVER then
local meta = _R[ “Player” ]
function meta:GetMoney()
return self:GetNetworkedInt(“Money”)
end
function meta:SetMoney()
self:SetNetworkedInt( “Money”, 100)
end
function meta:AddMoney()
self:SetMoney( self:GetMoney() + 5 )
end
timer.Simple( “givemoney”, 5, 0, function()
for k, v in pairs( player.GetAll()) do
v:AddMoney( 5 )
end
end )
else
function GetMoney()
return LocalPlayer():GetNetworkedInt( “Money” )
end
end[/lua]

And here is the draw.SimpleText code for where it shows the money:

[lua]

draw.SimpleText( LocalPlayer():GetNetworkedInt( “Money” ), “TextFontHUD”, middlex + 15, bottomy + 360, Color( 255, 255, 255, 200 ) )



Can someone please help me? Thanks.
[/lua]

First of all, you have the argument for **[Timer.Simple

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Timer.Simple)** wrong.

Also, You should change line 19 to this:
[lua]return LocalPlayer():GetNetworkedInt( “Money”, 0 )[/lua]
so that when the money hasn’t been set yet, it returns 0 not nil.

Thanks, it worked but it doesn’t give money every 5 seconds. It does at first, but never again.

That’s what timer.Simple does, it’s simply a delay on a single action. You need to use **[Timer.Create

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Timer.Create)**.

[lua]timer.Create( “my_timer”, 5, 0, function()
for k, v in pairs( player.GetAll()) do
v:AddMoney( 5 )
end
end )[/lua]

That’s what I changed it to.

Do you really need 3 threads for this?

This thread is different…I got the code, just it won’t work.

I got it to work now, but it doesn’t add it every 5 seconds. It adds $5 in the first 5 seconds, but then nothing else happens.

I already answered that, use timer.Create with a repeats number of 0. Do not answer “I tried that and it didn’t work” because if that’s the case you are doing something wrong.

It really didn’t work. But I have something different I used…

If it really didn’t work, then post the code that doesn’t work…

Then maybe someone can help you with your new timer code.

I got it to work.

Couldent you just have asked me who wrote that in the reply box :colbert:

[editline]09:36PM[/editline]

Also you got quite a few messups in that, lemme fix it to do what you want:
[lua]if SERVER then
local meta = _R[ “Player” ]
function meta:GetMoney()
return self:GetNetworkedInt(“Money”)
end
function meta:SetMoney(amount)
self:SetNetworkedInt( “Money”, amount)
end
function meta:AddMoney()
self:SetMoney( self:GetMoney() + 5 )
end
timer.Create( “givemoney”, 5, 0, function()
for k, v in pairs( player.GetAll()) do
v:AddMoney( 5 )
end
end )
else
function GetMoney()
return LocalPlayer():GetNetworkedInt( “Money” )
end
end[/lua]