You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? A friend asked me to script a “wardrobe system”, similar to Royale High’s one. For those who are not familiar with it, here’s how it looks like:
Basically, it let you sort each piece of clothing by Color and Style. Each outfit can be worn in-game (for free) or purchased using MarketplaceService. -
What is the issue? While I managed to make the sorting by color work using Value objects, I can’t figure out how to sort by Style. What I’d like to understand, is how I can set the “Style” value to the table’s name where each ID is. Here is the code:
local MS = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
local ClothesTable = require(script:WaitForChild("Clothes"))
local ClothesFrame = script.Parent.Main:WaitForChild("Clothes")
local ClothesTemplate = script:WaitForChild("Sample")
function getClothes()
for style,pieces in pairs (ClothesTable) do
for id,color in pairs(pieces) do
--The template part contains some Values containing the type of asset (shirt or pants), color and style. I can't figure out how to set the Style value to the table's name.
local CloneTemplate = ClothesTemplate:Clone()
local Purchase = CloneTemplate.Buy
local PI = MS:GetProductInfo(id)
CloneTemplate.Name = id
CloneTemplate.Type.Value = PI.AssetTypeId
CloneTemplate.Color.Value = color
CloneTemplate.Parent = ClothesFrame
CloneTemplate.Image = "https://www.roblox.com/asset-thumbnail/image?assetId="..id.."&width=420&height=420&format=png"
Purchase.Activated:Connect(function()
MS:PromptPurchase(Player, id)
end)
end
end
ClothesTemplate:Destroy()
end
getClothes()
local SelectionsFrame = script.Parent.Main:WaitForChild("Selections")
local ColorButtons = SelectionsFrame.Colors:GetDescendants()
local StyleButtons = SelectionsFrame.Styles:GetDescendants()
--Sort by Color
for i,button in pairs(ColorButtons) do
if button:IsA("TextButton") then
button.Activated:Connect(function()
for i,v in pairs(ClothesFrame:GetChildren()) do
if v:IsA("ImageButton") then
if button.Name:lower() == v.Color.Value then
v.Visible = true
else
v.Visible = false
end
end
end
end)
end
end
And here is the ModuleScript’s table with all the clothes IDs (it’s a bunch of random stuff i found in the catalog):
local Clothes = {
["Glam"] = {
[6524540459] = "blue",
[6477704287] = "red",
[6444593041] = "gold",
[5631240312] = "silver"
};
["Dark"] = {
[6500360755] = "black",
[6379790284] = "white",
};
["Sporty"] = {
[6544455379] = "red",
[6518310486] = "black",
};
["Fantasy"] = {
[2033670602] = "gold",
[6466806792] = "pink"
};
["Casual"] = {
[5091477772] = "blue",
[5494529238] = "yellow",
[6268143988] = "red",
[6267187487] = "green",
[6532665725] = "purple",
[6530714781] = "other"
};
["Men"] = {
[6539097465] = "other",
};
}
-
What solutions have you tried so far? I tried using table.find and table.unpack, but the last one simply returns
nil
. I’ve never worked with Tables like this before, so I’m quite lost. I probably made some mistakes in the way I set up everything.
Some parts of this post might be confusing, I apologize for that, so feel free to ask if you are unsure. I’ll try to explain the best way I can. Thanks in advance.