attempt to index global 'Math' (a nil value)

Hi for some reason i get an error when adding interest from bank.

attempt to index global ‘Math’ (a nil value)

Could somebody please help fix this error?


function AddInterest ( Player )
    local Amount = Math.round(Player:GetBank() * 1.25 - Player:GetBank())
    local VipAmount = Math.round(Player:GetBank() * 1.25 - Player:GetBank())
    if (!Player:IsVIP()) then
        Player:Notify( "$" .. Amount .. " Interest was added to your existing " .. Player:GetBank())
        Player:SetBank(Player:GetBank() + Amount)
    else
        Player:Notify( "$" .. VipAmount .. " Interest was added to your existing " .. Player:GetBank())
        Player:SetBank(Player:GetBank() + VipAmount)
    end
end
concommand.Add('pe_rp_int', AddInterest)

timer.Create( "Command", math.random(300,600), 0, function()
   RunConsoleCommand( "pe_rp_int" )
end )

it’s “math” not “Math”

as stated above, math is undercase.

Rule of thumb for Lua, Everything is case sensitive.

Also that console command looks exploitable, As it looks right now the player could fake the command in their console and get money.

If you are on GMod 13, tryout the Networked Library instead of console commands or datastream if you are using GMod 12.

Try putting this somewhere on the server.

[lua]
–EDIT BELOW
local r1 = 300 – The lowest possible amount of time between interest payouts
local r2 = 600 – The highest amount of time between interest payouts
local mult = 0.10 – The percent gain for regular players
local vipmult = 0.15 – The percent gain for VIP players
– DONT EDIT PAST THIS (Unless you want!)

hook.Add(“Think”, “PayInterest”, function()
– Loop through all the players. We want to account everybody!
for _, ply in pairs(player.GetAll()) do
– If they don’t have a time set to get their interest payment, lets set one! 300 to 600 seconds in the future.
if (!ply.nextInterest) then ply.nextInterest = CurTime() + math.random(r1, r2) end

    -- If it's not time for them to get paid yet, then lets skip this player and check the next.
    if (ply.nextInterest <= CurTime()) then continue end


    -- If we got here, then it's time to pay them. Lets start by setting the next payment time to nil so it'll reset when we come back to them in the loop.
    ply.nextInterest = nil


    -- Store the player's bank amount locally. I don't know if this function is intensive, so we're only going to call it once to be safe.
    local plybank = ply:GetBank()


    -- Setup the multiplyer.
    local percent = mult
    if (ply:IsVIP()) then 
        percent = vipmult -- VIP member percent gain
    end


    -- Figure out how much they should gain given their current bank amount
    local amount = plybank * percent


    -- Update their bank with the latest amount of money they should have
    ply:SetBank(plybank + amount)


    -- Lets notify the player, they wanna know they got the dosh!
    ply:Notify( "$"..amount.." Interest was added to your existing $"..plybank)
    
end

end)
[/lua]

That’s a lot better than what you’re doing.
(it should work…)

[editline]11th August 2012[/editline]

If it doesn’t let me know, but I was sure to comment it out nice for you! <3