Error when HumanoidDescription has 2 ids in 1 section

So basically, I’ve been scripting a character generator. When characters generate you can click on them and you can try on the outfit or u can buy the accessories in it.
Now I have an issue with the “buy accessory” part.
If a humanoiddescription section has 2 IDs it will bug my script. When there’s 1 id it works fine
How can I fix this?


image

local rep = game:GetService("ReplicatedStorage")
local p = game:GetService("Players").LocalPlayer
local of = p.OutfitFocus
local but = script.AccessoryButton

rep.OpenCharacterGui.OnClientEvent:Connect(function()
	p.PlayerGui.MainGUI.Try.Visible = true
	local humDesc = of.Value:FindFirstChild("Humanoid").HumanoidDescription
	local a = humDesc.BackAccessory
	local b = humDesc.FaceAccessory
	local c = humDesc.FrontAccessory
	local d = humDesc.HairAccessory
	local e = humDesc.HatAccessory
	local f = humDesc.NeckAccessory
	local g = humDesc.ShouldersAccessory
	local h = humDesc.WaistAccessory
	if a ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. a .."&width=420&height=420&format=png"
		newBut.Name = a
		print(a)
	end
	if b ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. b .."&width=420&height=420&format=png"
		newBut.Name = b
		print(b)	
	end
	if c ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. c .."&width=420&height=420&format=png"
		newBut.Name = c
		print(c)	
	end
	if d ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. d .."&width=420&height=420&format=png"
		newBut.Name = d
		print(d)	
	end
	if e ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. e .."&width=420&height=420&format=png"
		newBut.Name = e
		print(e)	
	end
	if f ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. f .."&width=420&height=420&format=png"
		newBut.Name = f
		print(f)	
	end
	if g ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. g .."&width=420&height=420&format=png"
		newBut.Name = g
		print(g)	
	end
	if h ~= "" then
		local newBut = but:Clone()
		newBut.Parent = script.Parent
		newBut.Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. h .."&width=420&height=420&format=png"
		newBut.Name = h
		print(h)	
	end
end)

Well it depends, when there are 2 ids what one do you want? The first one? The last one? Them all? or what?

1 Like

All of them together, so I can put them into the frame

Then just split the string into a table with “,”.

e.g.

local Tab = string.split(a, ",");

for _,v in pairs(Tab) do
    -- Do something with v
end;
1 Like