Can I make a TableValue?

Hey there!

I am working on my game, and I am going to add a pet upgrade feature! There are multiple pets with different kinds of upgrades, resulting in a lot of different sets of information to be put in a player. Now, I could put like 50 different int values in the player for each thing, but that obviously is a lot and very time consuming. I know you can put stuff in the player like this:

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = player

But is there a way to make it a table value? It also needs to be put in a datastore so that also complicates things…

1 Like

You can use a string value to store tables and use JSON to Encode/Decode the table to string format:

local HS = game:GetService("HttpService") 
local MyTable={Coins=0, XP=0}

MyStringVal.Value=HS:JSONEncode(MyTable)  -- Encodes to String

MyTable=HS:JSONDecode(MyStringVal.Value) -- Decodes back to Table
4 Likes

You can use a string value and store JSON, but it will not be able to serialize instances. Only strings, numbers, booleans and nil can be stored.

You should be using modules if you want to make a table that other scripts can access.

1 Like

Is there a way I can datasave modules?

You can save tables in datastores, but not modules. You would simply have to require it.

And instances cannot be saved in them too.

1 Like

If I was you I will save every ‘pet feature’ with ID to modulescript (table) and specify everything in there and then you will make table as others stated where you gonna store the ID of the pet feature.

1 Like