• Saving / Loading players data with PData returning a nil value
    7 replies, posted
From what I see this should be fairly simple to save / load data and network it with SetNWInt.. but I keep getting a nil value I've attempted this in about 5 different variations. The code below is my last attempt. The code is also running on the server in init.lua function load()   if player:GetPData("Money") == nil then     player:SetPData("Money", 500)     player:SetNWInt("Money", 500)     print("new")   else     player:SetNWInt( player:GetPData("Money")) print("back")   end end Any help / recommendation would be awesome!
Maybe "Money" is a keyword being used by something else and is conflicting with it.
Just tried to change them all to plymoney to see if that would make a difference and still the same error..
player:SetNWInt( player:GetPData("Money")) This is missing a name. What's "player" in this context?
If you're receiving something similar to attempt to call method 'GetPData' (a nil value), i'm having the same problems... I'll let you know if I find a fix for it. I'll try help you now though... Can you post your full error?
That was a bad attempt at me trying to fix it here is my original code I was working with. I believe it's still just because it's not finding the player or my ply variable holds no data which is what is bugging this - could this be because I am calling it on PlayerInitialSpawn and that uses ply as well and they're confusing one another? Excuse any syntax errors in this as I had to rewrite this out at work I might have a typo.. local ply = FindMetaTable( "Player" ) function ply:saveStats() self:SetPData("Money", self:GetNWInt("Money")) end function ply:loadStats() if self:GetPData("Money") == nil then self:SetPData("Money", 500) self:SetNWInt(Money, 500) else self:SetNWInt("Money", self:GetPData("Money")) end end I can not post the error right now as I'm at work but that sounds right the error is happening on loadStats at the IF stating the value is nil.. Also as a note I am running this in playerstats.lua which is included into my init.lua with include("server/playerstats.lua") so it's running all on server side which is what I believe I need to do to save the players stats. I'm new so I could be making a stupid mistake trying to give as much information as I can.
Player/GetPData returns a string, Entity/SetNWInt takes a number. Also can you post where you're running said code.
I did get it working - it was the way I was setting up my function and trying to pass the player to it. was never receiving any players information causing the error to happen...
Sorry, you need to Log In to post a reply to this thread.