Lua Help with nil value!

Hey, I am making a gamemode. I am making a money system, and I keep getting this error:



Timer Error: GamemodeName/gamemode/init.lua:50: attempt to index local 'pl' (a nil value)


Here is the entire init.lua file( not that big ):



function GM:PlayerInitialSpawn( pl )
timer.Start( "MoneyTimer" )
SetMoney( pl, 100 )
end

function GM:PlayerLoadout( pl )
	pl:Give( "weapon_crowbar" )
end

//This will make HelpMenu popup with F1

function GM:ShowHelp( pl )
	umsg.Start( "HelpMenu", pl )
	umsg.End( )
end

//This will make Inventory popup with F2

function GM:ShowTeam( pl )
	umsg.Start( "Inventory", pl )
	umsg.End( )
end

//This will make PlayerStat popup with F3

function GM:ShowSpare1( pl )
	umsg.Start( "PlayerStat", pl )
	umsg.End( )
end

//This will make Shop popup with F4

function GM:ShowSpare2( pl )
	umsg.Start( "Shop", pl )
	umsg.End( )
end

local MoneyGiveTime = 5
local MoneyGiveAmount = 5
local MoneyStartAmount = 100

function GetMoney( pl )
	return pl:GetNetworkedInt( "Money" )
end

function SetMoney( pl )
	pl:SetNetworkedInt( "Money", 100 )
end

function AddMoney( pl )
	local currentcash = GetMoney( pl )
	SetMoney( pl, currentcash + 5 )
end
timer.Create( "MoneyTimer", 5, 0, function() 
	for k, v in pairs(player.GetAll()) do AddMoney() end
end )


Can someone help me fix that code? Thanks.

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

lua tags over code tags when posting Lua.

What do you mean?

He means you should use [ lua][ /lua] tags And then he posted the working code.

Oh, and it didn’t work. I still get the same error:




Timer Error: GamemodeName/gamemode/init.lua:50: attempt to index global 'pl' (a nil value)



This is line 50:
[lua]
return pl:GetNetworkedInt( “Money” )
[/lua]

And this is the whole function for line 50:
[lua]
function GetMoney( pl )
return pl:GetNetworkedInt( “Money” )
end
[/lua]

Add some prints. for example:
[lua]
function GM:PlayerInitialSpawn( pl )
timer.Start( “MoneyTimer” )
SetMoney( pl, 100 )
end

function GM:PlayerLoadout( pl )
pl:Give( “weapon_crowbar” )
end

//This will make HelpMenu popup with F1

function GM:ShowHelp( pl )
umsg.Start( “HelpMenu”, pl )
umsg.End( )
end

//This will make Inventory popup with F2

function GM:ShowTeam( pl )
umsg.Start( “Inventory”, pl )
umsg.End( )
end

//This will make PlayerStat popup with F3

function GM:ShowSpare1( pl )
umsg.Start( “PlayerStat”, pl )
umsg.End( )
end

//This will make Shop popup with F4

function GM:ShowSpare2( pl )
umsg.Start( “Shop”, pl )
umsg.End( )
end

local MoneyGiveTime = 5
local MoneyGiveAmount = 5
local MoneyStartAmount = 100

function GetMoney( pl )
print(“GetMoney:”, pl)
return pl:GetNetworkedInt( “Money” )
end

function SetMoney( pl )
pl:SetNetworkedInt( “Money”, 100 )
end

function AddMoney( pl )
print(“AddMoney:”, pl)
local currentcash = GetMoney( pl )
SetMoney( pl, currentcash + 5 )
end
timer.Create( “MoneyTimer”, 5, 0, function()
for k, v in pairs(player.GetAll()) do print(“MoneyTimer:”, v) AddMoney(v) end
end )
[/lua]

Nevermind. It worked. I had a typo. Dumb. Thanks everyone.