Player data with tables.

Hi Facepunch users! Recently I try to set player data (setPData) with table.



ply.rantable={["SprintMeter"]={1,1,0},["DuckMeter"]={1,1,0},["WalkMeter"]={1,1,0},["JumpMeter"]={1,1,0}}
ply:SetPData("Meters",ply.rantable)


I try many ways. Print all values and tables.



] lua_run for k,v in pairs(Entity(1):GetPData("TEST",{3,2,1})) do print(v) end
> for k,v in pairs(Entity(1):GetPData("TEST",{3,2,1})) do print(v) end...
[ERROR] lua_run:1: bad argument #1 to 'pairs' (table expected, got string)
  1. pairs - [C]:-1
   2. unknown - lua_run:1


If I print standart table all works!



] lua_run for k,v in pairs(ply.rantable) do print(k) for i,m in pairs(v) do print(m) end end
> for k,v in pairs(ply.rantable) do print(k) for i,m in pairs(v) do print(m) end end...
SprintMeter
1
1
0
WalkMeter
1
1
0
DuckMeter
1
1
3
JumpMeter
1
1
0


How to save table in Data Base(no mysql)?

You can’t store tables in SetPData. You can, however, store JSON strings and then convert it back to a table and loop through it.

How to use it?

Convert your table into a JSON string.
Store the string in the player data.
Read the player data.
Convert the string back to a table.