How to store tables in instances?

Hello, so I want to store a table in an instance. My only question is, how can I do it? I’ve tried searching but can’t find a single thing on it. Any help is appreciated!

I don’t think there’s a table instance. The closest I can think of would be a data store. What are you even trying to do?

I dont think you know what I mean. I mean how can I put a table inside of an instance

Assuming this is what you want, you can put a folder inside the object and values (bool, int, etc) inside of it, or you can use subtables if you have a module:
image

1 Like

I’ll try this. Give me a second.

An object itself is a table so maybe try setting a metatable???

Try making a folder + values in it so you can : GetDescendants on the folder to get the table.

1 Like

I’ve gone ahead and did this.

local MyTable = {script.Parent}
local function ChangeTable()
	local NewTable = {}
	for i,v in pairs(MyTable) do
		local MyTable2 =  setmetatable({Data = {
		
			["ObjectData"] = {
				
					
				["Equipped"] = true,
				["Object"] = v
				
				
				
			}
	}}, NewTable)

		return MyTable2
		end
end

local MYTable = ChangeTable()
print(MYTable)

what it prints:

image

You can save them in a simple module giving it a unique key

Code
local M, Storage = {}, {}
function M.Set(Name:string, Table)
	Storage[Name] = Table
end
function M.Get(Name:string)
	return Storage[Name]
end

return M

but there is also this way, you shouldn’t, because for this it is not used, but it could be useful since it does not give an error, using LocalizationTable and giving it tables with this format

Code
LocalizationTable:SetEntries({
	[1] = {
		["Context"] = "",
		["Example"] = "",
		["Key"] = "",
		["Source"] = "",
		["Values"] = {
			["key"] = "value",
		}
	},
})

allows you to save strings, you could also save other things that can be formatted with JSONEncode.


To add another would be like this

Code
LocalizationTable:SetEntries({
	[1] = {
		["Context"] = "",
		["Example"] = "",
		["Key"] = "",
		["Source"] = "Player_A",
		["Values"] = {
			["key"] = "value",
		}
	},
	[2] = {
		["Context"] = "",
		["Example"] = "",
		["Key"] = "",
		["Source"] = "Player_B",
		["Values"] = {
			["key"] = "value",
		}
	},
})

Key cannot be the same as another, this is more of a curiosity.


Also you can also import the table from a .csv file

Example

.csv file


Output:
image
Code:

for _, T in pairs(LocalizationTable:GetEntries()) do
	local Player = T.Source
	local Inventory = T.Values
	print(Player, Inventory)
end

Note: this is not what LocalizationTable was created for.

5 Likes

I’ll give you the solution since you deserve it :slight_smile:

1 Like