How to get PData to work in Gmod 13?

I have been trying to get PData to work and It’s giving me PData “a nil value” errors.

Could somebody tell me the correct way of using it?

Post your code.

GetPData and SetPData should work fine.

I am having this same problem, everything seems fine but here is my code.

 	if self:GetPData( "money" ) == nil then
	self:SetPData( "money", 250 )
	elseif self:GetPData( "rank" ) == nil then
	self:SetPData( "rank", 1 )
	elseif self:GetPData( "banstatus" ) == nil then
	self:SetPData( "banstatus", 0 )

That is returning a nil value on ‘GetPData’

Those functions are server-side. You cannot run them on the client.

[lua]DermaButton.DoClick = function( ply )
player:SetPData( “rpnamecheck”, 1 )[/lua]

I have tried ply:SetPData and self:SetPData and there is always an error.

You cannot run Player.SetPData on the client.

Ok so I am using a Derma Box to popup on join to ask the player to enter a roleplay name. Now it works but I need it to remember that they already did it.

Derma stuff only seems to work on the client so how would I get PData to to set when the player hits the OK button?

Make it run a concommand to send it to the server, SetPData there.

Look up concommand.Add if you need to.

Ok that is all nice but how can I make the “Question1” DermaBox popup when a player spawns.

If you add me on steam, I wouldn’t mind giving you a hand for free. I enjoy helping people.

Garry’s Mod Wiki is there for a reason, use it and stop trying to get people to code for you, we’re here to help you when you have troubles with LUA, this is a request. (The derma part)

The other one was answered, you can’t set private data client-side, you need to use concommand’s or net library.

is PData networked variables?

Anyone getting this problem? PData isn’t saving.

Post your code. PData is working fine for me.

function SetupPlayerXP(ply)
    local steamid = ply:SteamID()
	if ply:GetXP()==nil then
		SaveLevel(steamid, 0)


GetPData(“exp”) is returning nil

I don’t see where GetPData(“exp”) is called anywhere

function Player_ENT:GetXP()
	return tonumber(self:GetPData("exp")) or 0

you can do self:GetPData( “exp”, 0 ) by the way

Ok, but does anyone know why its returning nil?

It will never be nil because you’re returning 0 if it is nil.