I don't know how to put a table in a table

  1. **I want to insert a table in a table but I don’t know how to do it **

  2. **I print my table but thats not a table in a table thats just 1 table with my values and the name of my auras
    image
    ** Include screenshots / videos if possible!

  3. **I tried the to find solutions on the dev hub but none worked so if you can help me Ill appreciate it :slight_smile: **

Here is my script so save the auras
image

here the one to load the auras
image

2 Likes

Just like you insert any value:

local t1 = {"foo", "bar"}
local t2 = {4, 6, 2}

table.insert(t2, t1) 
print(t2) --{4, 6, 2, {"foo", "bar"}}
2 Likes

What I would do is this:

local table1 = {}
local table2 = {}
local value1 = "Hello, World!"
local value2 = 0
table.insert(table2, value1)
table.insert(table2, value2)
table.insert(table1, table2)

basically, you Add the items to the table, then append the table to the other table.

1 Like
outerTable = {
	value1 = 10,
	innerTable1 = {
		value1 = 20,
		value2 = 30  -- could use a , here or not
	},
	innerTable2 = {
		value1 = 40,
		value2 = 50,
		innerTable2innerinnerTable1 = {
			value1 = 60 -- last value don't need a , but could still have one
		}
	}
}

print(outerTable.value1)
print(outerTable.innerTable1.value1)
print(outerTable.innerTable1.value2)
print(outerTable.innerTable2.value1)
print(outerTable.innerTable2.value2)
print(outerTable.innerTable2.innerTable2innerinnerTable1.value1)

t1 = {
	value1 = 10,
	t2 = {
		value1 = 20,
		value2 = 30
	}
}

print(t1.value1)
print(t1.t2.value1)
print(t1.t2.value2)

Table names don’t matter, just the format.

1 Like

that return me this
image

but I want a table in the BasicBee for exemple how can I do it ?

1 Like

But in my script I dont have a preset for the table but I want your form of table at the end (idk if im clear my english is a bit bad sry)

1 Like

Oh, so you’re looking for a dictionary? Something like:

local tbl = {
    BasicBee = {0,0,0,0},
    BomberBee = {0,0,0,0},
    BraveBee = {0,0,0,0},
    HastyBee = {0,0,0,0},
}

this?

1 Like

yeah with only 1 value in the dictionary not 4 like you showed

1 Like

you can have something like this in a script:

local a = {}
a["honey"] = 20;

print(a)

--[[ output in studio:
a = {
    ["honey"] = 20
}
]]
1 Like

What do you mean? I’m a little confused, but if you mean the {0,0,0,0}, you can change that to your liking, for example:

local tbl = {
    BasicBee = "Basic",
    BomberBee = "Bomber",
    BraveBee = "Brave",
    HastyBee = "Hasty",
}

or

local tbl = {
    BasicBee = Color3.new(0,0,1),
    BomberBee = Color3.new(1,0,1),
    BraveBee = Color3.new(0,0,0),
    HastyBee = Color3.new(1,1,0),
}

I was simply going off what I saw in your output screenshots.

1 Like

In the case of you only needing one value in the dictionary, couldn’t you just not use a dictionary? You can just define a value in the table as QualityControl said.

1 Like

I want this table in the output

{
BasicBee = (value of the player) 
BomberBee = (value of the player) 
BraveBee = (value of the player) 
HastyBee = (value of the player) 

}
1 Like
local tbl = {}
tbl["BasicBee"] = 0 (change to your value of the player)
tbl["BomberBee"] = 0 (change to your value of the player)
tbl["BraveBee"] = 0 (change to your value of the player)
tbl["HastyBee"] = 0 (change to your value of the player)

1 Like

I’d really like to know the context of this table, because I don’t know why you’d want to store the player (assuming it’s the owner) in each bee type.

2 Likes

When the player load I have an inventory system with a limit and when the player load I want to know the amount of bee the player have thats why I want this table

In that case, why wouldn’t any of the above responses work for you?

local function saveAmountAuras(player)
	local AurasValues = player.AurasValues
	if not AurasValues then
		warn("AurasValues not found for player "..player.Name)
		return
	end
	
	local AuraAmount = AurasValues:GetChildren()
	local auraName = {}
	local AuraValues = {}
	
	for _, aura in ipairs(AuraAmount) do
		if aura:IsA("IntValue") then
			table.insert(auraName, aura.Name)
			table.insert(AuraValues, aura.Value)
			table.insert(auraName, AuraValues)
			
			print(auraName)
		end
	end
	
	local success, errorMsg = retryOperation(function()
		AmountAuraData:SetAsync(player.UserId, auraName)
		print("saved")
	end)
	
	if not success then
		warn("Failed to save auras for player "..player.UserId..": "..errorMsg)
	end
end

cause I need to get the auraName and not a pretable idk if im clear im sorry im a beginner

{
auraName = (value of the player) 
}

In this case, the code in the function would look like:

local function saveAmountAuras(player)
	local AurasValues = player.AurasValues
	if not AurasValues then
		warn("AurasValues not found for player "..player.Name)
		return
	end
	
	local auras = AurasValues:GetChildren()
	local auraAmounts = {}

	for _,aura in ipairs(auras) do
		if not aura:IsA("IntValue") then continue end
		auraAmounts[aura.Name] = aura.Value -- Save the quantity of auras with the aura's name
	end
	
	local success, errorMsg = retryOperation(function()
		AmountAuraData:SetAsync(player.UserId, auraAmounts)
		print("saved")
	end)
	
	if not success then
		warn("Failed to save auras for player "..player.UserId..": "..errorMsg)
	end
end

Thank you for helping me :heart: I really have to learn how table works sorry :slight_smile:

No problem, it’ll be a godsend when you figure out how to use dictionaries.

1 Like