Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a better and simpler and more efficient way to put this code?

local Tab = {Inventory = {}, Backpack = {}}

local Data = {Inventory = {'G','S','F','A'}, Backpack = {'G','S','R','F.',"A"}}

for i,v in pairs(Data) do
	if Tab[i]then
		for c,d in pairs(v) do
			table.insert(Tab[i],d)
		end
	end
	
end

---

for i,v in pairs(Tab.Backpack) do
	print(i,v)
end

for i,v in pairs(Tab.Inventory) do
	print(i,v)
end

Im trying to insert everything according to the keys this is for a datastore

But I was wondering if there was a simpler way to do this

1 comment

0

You could just do arrays but that would take up far too much time

1 answer

Unless you've oversimplified your example to the point where it does not represent your actual problem, what you coded up is a loop you should replace with the hardcoded result:

local Tab = {
	Inventory = {'G','S','F','A'},
	Backpack = {'G','S','R','F.',"A"},
}

Is what you're actually trying to code a generic, recursive table deep-copy?

This discussion is preserved as it was. New answers, comments, and votes are closed.