How can i get every value inside the table then split them up into 3

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the ColorTable to get every value inside the table(the rarity that is picked) example: [255,255,255]

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    found a bunch of posts but none of them worked.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local EggHatch = {}

local Eg = script.Parent
local Pets = game.ReplicatedStorage.Pets:WaitForChild(“BasicEgPets”)
local FireShowcase = game.ReplicatedStorage.Events:WaitForChild(“FireShowcase”)

EggHatch.Color = {-- colors for the copied egg

["Legendary"] = {242, 255, 0},

["Epic"] = {202, 22, 234},

["Rare"] = {39, 179, 255},

["UnCommon"] = {17, 255, 0},

["Common"] = {255,255,255} 

}

EggHatch.Pet = { – eggs inside folder

["Legendary"] = {
	Pets.Legendary:GetChildren()
},

["Epic"] = {
	Pets.Epic:GetChildren()
},
["Rare"] = {
	Pets.Epic:GetChildren()
},
["UnCommon"] = {
	Pets.Uncommon:GetChildren()
},

["Common"] = {
	Pets.Common:GetChildren()
}

}

EggHatch.rarities = {

["Legendary"] = 2,
["Epic"] = 5,
["Rare"] = 20,
["UnCommon"] = 35,
["Common"] = 65,

}

function EggHatch.Hatch(plr)

local RandomNum = math.random(1,100)

RandomNum += math.random(1,10) or 0

local counter = 0

for rarity, weight in pairs(EggHatch.rarities) do
	counter += weight
	if counter >= RandomNum then
		local RarityTable = EggHatch.Pet[rarity]
		local ColorTable = EggHatch.Color[rarity] -- problem here, it only grabs one value not the rest inside the table
		print(RarityTable)
		print(ColorTable)
		local ChosenPet = RarityTable[math.random(1,#RarityTable)]
		print(ChosenPet)
		if ChosenPet then
			FireShowcase:FireClient(plr, ChosenPet, Eg, ColorTable)
			break
		end
	end
end

end

return EggHatch

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Why don’t you just store the color table as actual color values?

EggHatch.Color = {-- colors for the copied egg

["Legendary"] = Color3.fromRGB(242, 255, 0),

["Epic"] = Color3.fromRGB(202, 22, 234),

["Rare"] = Color3.fromRGB(39, 179, 255),

["UnCommon"] = Color3.fromRGB(17, 255, 0),

["Common"] = Color3.fromRGB(255,255,255)
}
1 Like

Imo, this should work as the whole table is indexed at a rarity key and thus will be returned as a whole table.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.