Why does this not work?

Just as the title says.

[lua]function GM:PlayerAuthed( pl, SteamID, UniqueID )
pl:SetPData( “total_points”, 0 )
pl:SetPData( “sequence_points”, 0)
pl:SetPData( “function_points”, 0)
pl:SetPData( “iterative_points”, 0)
pl:SetPData( “selection_points”, 0)
end[/lua]

[lua]function Add_Total_Points(ply, no_of_points)
print (“Adding Points”)
print ("Number of points to add "… no_of_points)
ply:SetPData(“total_points”, ply:GetPData(“total_points”) + no_of_points)
ply:SetNWInt(“tpoints”, ply:GetPData(“total_points”))
print (“points added, new balance”… ply:GetPData(“total_points”))
end
concommand.Add(“Add_Total_Points”, Add_Total_Points)[/lua]

[lua]function PANEL:ApplyEdit(pl)
local Text = self:GetEntryValue();

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

if function_name == "addpoints" then
	local no_of_points = 20
	Add_Total_Points(pl, no_of_points)
	//RunConsoleCommand("Add_Total_Points", pl, no_of_points);
    end

end[/lua]

I end up getting the error:
Adding Points
Number of points to add 20
includes/extensions/player.lua:147: attempt to call method ‘UniqueID’ (a nil value)

I also tried to call it with the console command which did not work at all, as I get this error: “attempt to perform arithmetic on local ‘no_of_points’ (a string value)”, unless I use…

[lua]function Add_Total_Points(ply, no_of_points)
print (“Adding Points”)
print ("Number of points to add "… no_of_points)
ply:SetPData(“total_points”, ply:GetPData(“total_points”) + 20)
ply:SetNWInt(“tpoints”, ply:GetPData(“total_points”))
print (“points added, new balance”… ply:GetPData(“total_points”))
end
concommand.Add(“Add_Total_Points”, Add_Total_Points)[/lua]

Which is just inconvenient, I see no reason why this would not work…

For anyone which takes the time to read/answer thanks in advance :slight_smile:

GM:PlayerAuthed( (Player) ply, (String) SteamID )

There is no uniqueID argument replace your first lump of code with:



function GM:PlayerAuthed( pl, SteamID )   
    pl:SetPData( "total_points", 0 )   
    pl:SetPData( "sequence_points", 0)   
    pl:SetPData( "function_points", 0)   
    pl:SetPData( "iterative_points", 0)   
    pl:SetPData( "selection_points", 0)   
end 

Thanks for the reply, but even changing it to that gives me the same error: “includes/extensions/player.lua:147: attempt to call method ‘UniqueID’ (a nil value)”

Grr this is driving me crazy!

I am guessing it has something to do with my second chunk of code as that’s where the error is getting pulled up.

try:



function Points_PlayerAuthed( pl, SteamID )   
    pl:SetPData( "total_points", 0 )   
    pl:SetPData( "sequence_points", 0)   
    pl:SetPData( "function_points", 0)   
    pl:SetPData( "iterative_points", 0)   
    pl:SetPData( "selection_points", 0)   
end
hook.Add("PlayerAuthed", "Points_PlayerAuthed", Points_PlayerAuthed);


Still getting that same damn error. But thank you once again!

Also, concommands have specific arguments (you can’t just make up your own). It’s always function(ply,cmd,args) - player, command, arguments. For example, if I type sv_gravity 0 in console, the player is me, the command is sv_gravity, and the args[1] is zero (args is a table).

So in your case, no_of_points would be args[1], if that’s what you’re getting at.

ah! Thank you I did not know that :slight_smile:

edit: What a hero you are! Making that simple change has fixed all my problems :smiley: Thanks a million :slight_smile:

[editline]07:31PM[/editline]

Okay now it all works perfectly for myself, but when my friend joins he faces the same problem that when he tried to add points he gets the same error: “includes/extensions/player.lua:147: attempt to call method ‘UniqueID’ (a nil value)”

But I am still able to give myself points perfectly fine…

do you think it could be a problem of where I put the Adding points code?