So I have this basic table which contains all information of objects used in my game. But as you can see in the table, the name of each object has its own table, meaning that I cannot get the name of the object normally because it’s technically a table, not a string.
local PlaceSoundsFolder = script.Parent:WaitForChild("BuildSounds")
local BuildingParts = {
["Tiny Engine"] = {
Category = "Engine",
Class = "Engine",
IconId = "6219814488",
Price = 250,
Description = "A really small engine",
BuildSound = PlaceSoundsFolder:WaitForChild("HardMetal"),
Purchasable = true,
},
["Large Engine"] = {
Category = "Engine",
Class = "Engine",
IconId = "6219814488",
Price = 10000,
Description = "A really big engine",
BuildSound = PlaceSoundsFolder:WaitForChild("HardMetal"),
Purchasable = true,
},
}
print(BuildingParts["Tiny Engine"]) -- Returns table. Need it to return the name of the table instead
Well, I’m making a vehicle builder game which has a GUI with a list of parts that you can place, and each button within that list has its own function.
I mean, having a loop isn’t a problem, but for me, loops are just too big for small functions like this.
for i, PartInfo in pairs(BuildPartsDictionary) do -- That table from earlier
if PartInfo.Category == PartCategory then
local PartButton = PartListFrame.TemplateButton:Clone()
PartButton.Name = PartInfo
PartButton.PriceText.Text = "$" .. PartInfo.Price
PartButton.LayoutOrder = PartInfo.Price
PartButton.NameText.Text = PartInfo
PartButton.Image = "http://www.roblox.com/asset/?id=" .. PartInfo.IconId
PartButton.Parent = PartListFrame
PartButton.MouseButton1Click:Connect(function()
SelectModel(PartInfo) -- errors because the table is not a string.
end)
end
end