Giving points to a player?

Hi there I am having a bit of trouble adding points to a player and wondering if anyone could give me some insight on what to do next, I have tried a couple of ways but I always hit a dead end, with an error saying “attempt to index global ‘pl’ (a nil value)” or something to that extent

So far in my init.lua I have

[lua]function GM:PlayerAuthed( pl, SteamID, UniqueID )
pl.total_points = pl:GetPData( “TotalPoints”, 0 )
pl:SetNWInt( “points”, pl.total_points )
end
[/lua]

[lua]function GM:PlayerInitialSpawn(pl)
pl:SetNWInt(“dead”, 0)
pl:SetTeam(TEAM_SPECTATOR)
pl:ConCommand(“gm_showteam”)
pl.switched_this_round = false

pl.total_points = pl.total_points or 0

end[/lua]

And then my scoreboard reads the points easily like so it it’s own scoreboard file…

[lua]function PANEL:UpdatePlayerRow(pl)
self.name_label:SetText(self.pl:Name())

if self.pl:GetNWInt("dead") == 1 then
	self.dead_label:SetText("Dead")
else
	self.dead_label:SetText("")
end

for k, ply in pairs( player.GetAll() ) do
	local t_points = ply:GetNWInt( "points")
	self.total_points_label:SetText(t_points)
end

self:InvalidateLayout()

end[/lua]

Now I have another file which is used to read input from a textbox where the user can input data and receive points, depending on what they have input, and I am having trouble giving the points to the player.

[lua]
function PANEL:ApplyEdit()
local Text = self:GetEntryValue();
local points = ply:GetPData(“TotalPoints”)

local function_name, count = Text:match( "([%w_]+)%((%d+)%);" );

ply:SetPData("TotalPoints", points + count)
if function_name == "add_points" then

end

end[/lua]

I would expect that to work but all I get is the error: “attempt to index global ‘ply’ (a nil value)”

Would anybody be kind enough to shed some light on my problem, possible tell me where I am going wrong, and what file to put this adding points thing in?

Thank you in advance!

Ply isn’t defined in your third function.

silly me!

I have figured out a way to give the player points now, but I do not think it works correctly…

so far I have in my init.lua:
[lua]function GM:PlayerInitialSpawn(pl)
pl:SetNWInt(“dead”, 0)
pl:SetTeam(TEAM_SPECTATOR)
pl:ConCommand(“gm_showteam”)
pl.switched_this_round = false
pl:SetPData( “points”, 0 )
end[/lua]

Then in my shared.lua I have:
[lua]function AddPoints(pl, command, args)
print (“Adding Points”)
pl:SetNWInt(“points”, pl:GetNWInt(“points”) + 20)
print (“points added, new balance”… pl:GetNWInt(“points”))
end
concommand.Add(“AddPoints”, AddPoints)[/lua]

which of course gets called when I want to add points, now this works when playing on my own but as soon as someone else joins the server, the other player just see’s all 0’s and when ever he adds points it gets added to both of us on their screen…?

Is there something wrong with the way I am giving points, as it appears to not be working at all, lol

Also I tried to use pl:SetPData & pl:GetPData but whenever I try to use them all I get is the error… “includes/extensions/player.lua:147: attempt to call method ‘UniqueID’ (a nil value)”

Do I need to do anything special to start using those functions?

EDIT: Infact using pl:GetPData anywhere in my game mode results in that damn error…