[SOLVED]How to turn a table inside of a table to a string

Hello, I have a little problem

local LootPlan = require(game:GetService("ReplicatedStorage").LootPlan)
local orePlan = LootPlan.new("single")
local oreInfo = {
    ["Coal"] = {
        ["Color"] = Color3.new(0.14902, 0.14902, 0.14902),
        ["Amount"] = 3,
        ["Delay"] = 0.55,
        ["Rarity"] = 5
    },
    
    ["Copper"] = {
        ["Color"] = Color3.new(0.745098, 0.12549, 0.0431373),
        ["Amount"] = 3,
        ["Delay"] = 0.6,
        ["Rarity"] = 5
    }
}

for i, ore in pairs(oreInfo) do
    orePlan:AddLoot(ore, ore.Rarity) -- This is the issue, it selects the table coal, copper, and other ores I'll add later on
end

How do I make it not select it as a table, even though it is, because when I do this:

local chosenOre = orePlan:GetRandomLoot()
local ore = game.ServerStorage.Ores.Stone:Clone()
    ore.Position = newPos
    ore.Parent = workspace.Cubes
    ore.Name = chosenOre
    ore.Color = chosenOre.Color

this happens

ServerScriptService.OreGeneration.oreGeneration1:78: invalid argument #3 (string expected, got table)  

tostring makes the weird table key with random characters, tried searching on the devforum but as long as I can see , I’m either dumb or nobody talked about them

You use chosenOre table in ore.Name = chosenOre as a name, its index is not a name of a table, so you have to make a chosenOre.Name property in the table.

Hope this helps!

2 Likes

Thank you so much, it worked! I had no idea it was because of that

table.concat() can be used to convert a table into a single string value.

local someTable = {"a", "b", "c"}
local stringTable = table.concat(someTable, "~") --2nd argument is the delimiter
--output a~b~c

But yeah, your ores were missing a name property, currently you were attempting to assign the entire table as the name of the ore.

1 Like

Another viable alternative to writing an individual name Index is to attach a metatable and use __tostring, which will be invoked any time the table tries to get used as a string. Just depends how much functionality you need.

1 Like

Yes, I know and I’m happy it’s fixed now

jakjsjajsabahahha