I am making a warning system and saving stopped working I am using PData and not sure when it stopped working and I have made plenty of changes between that time. it did work before btw.
function InitializePlayerData(ply)
if (ply:GetPData("Warnings") == nil) then
ply:SetPData("Warnings", 0)
ply:SetNWInt("Warnings", 0)
else
ply:SetNWInt("Warnings", ply:GetPData("Warnings"))
end
end
hook.Add("PlayerInitialSpawn", "InitializePlayerData", InitializePlayerData)
function SaveDisconnectedPlayerData(ply)
ply:SetPData("Warnings", ply:GetNWInt("Warnings"))
end
hook.Add("PlayerDisconnected", "SaveDisconnectedPlayerData", SaveDisconnectedPlayerData)
hook.Add( "PlayerSpawn", "SaveSpawnedPlayersData", SaveDisconnectedPlayerData )
function SaveAllPlayerData(ply)
for k, v in pairs(player.GetAll()) do
v:SetPData("Warnings", v:GetNWInt("Warnings"))
end
end
hook.Add("ShutDown", "SaveAllPlayerData", SaveAllPlayerData)
timer.Simple( 300, function() SaveAllPlayerData() end )
How exactly does it not "work"
function SaveDisconnectedPlayerData(ply)
ply:SetPData("Warnings", ply:GetNWInt("Warnings"))
end
hook.Add( "PlayerSpawn", "SaveSpawnedPlayersData", SaveDisconnectedPlayerData )
Problem might be here, I don't see any reason why you will need to save it each time player spawns
Also, Player/GetPData says it returns string, not number
if (ply:GetPData("Warnings") == nil) then
ply:SetPData("Warnings", 0)
ply:SetNWInt("Warnings", 0)
else
ply:SetNWInt("Warnings", ply:GetPData("Warnings"))
end
-- this code block can be simplified to
ply:SetNWInt("Warnings", ply:GetPData("Warnings", 0))
shouldn't it be tonumber(ply:GetPData("Warnings",0)) in that case
it doesnt save how do u think a saving system doesnt work lol
What exactly is the point of this?
timer.Simple( 300, function() SaveAllPlayerData() end )
Also, it seems as if you didn't really look into the issue on your own properly before posting to get help. Try adding some prints to see if your functions are running because if the issue was indeed a hook not running you would've seen so pretty much instantly.
Timer Simple creates a timer for 300 seconds or 5 minutes and does a save every 5 minutes so when the server crashes it will have a decent save
I looked into the issue my self and found the issue my self, it seems you are being a douchbag and it wasnt that the hook wasnt running it got confused because i used this same exact method for my level system and there was no error, you are being a dick my issue was solved now fuck off.
He is just simply suggesting some basic debugging help in order to solve similar issues in the future - you are taking it way off base and being unnecessarily abrasive.
He assumed i did not do that, and the fact i already fixed the error and he knew that i took it personally and i already did that i just didnt include that part in the code i shared becuase it is not part of the og code that i wanted fixed.
Apart from all the nonsense being posted here, you should probably look into using net messages and controlling everything serverside. Whenever a warning is added/removed then update the PData on the spot so that you don’t have to worry about data being lost on a crash.
Sorry, you need to Log In to post a reply to this thread.