How to code a cloned table of accessories able to be added to characters?

Kinda wordy and on the nose, but exactly that. I’ve cloned a table of accessories, but how do I apply them to the character?

local StandardShirt = {ClothingFolderEly.ElyStanCollar, ClothingFolderEly.ElyStanShirt, ClothingFolderEly.ElyStanRSleeve, ClothingFolderEly.ElyStanRSleeve, 
 ClothingFolderEly.ElyStanLShoulder, ClothingFolderEly.ElyStanRShoulder}

GiveClothingEvent.OnServerEvent:Connect(function(Player)
	local ClonedShirt = table.clone(StandardShirt)
end)

I got this, but I’m not sure how to actually make it work.

for i,v in pairs(table) do
 Player.Character.Humanoid:AddAccessory(v)
end

For some reason it only works once? If the character dies, it just doesn’t work anymore.

local StandardShirt = {ClothingFolderEly:WaitForChild("ElyStanCollar"), ClothingFolderEly:WaitForChild("ElyStanShirt"), ClothingFolderEly:WaitForChild("ElyStanPantsWaist"),
		ClothingFolderEly:WaitForChild("ElyStanRSleeve"), ClothingFolderEly:WaitForChild("ElyStanLSleeve"), ClothingFolderEly:WaitForChild("ElyStanLShoulder"), 
		ClothingFolderEly:WaitForChild("ElyStanRShoulder")}

GiveClothingEvent.OnServerEvent:Connect(function(Player)
	local ClonedShirt = table.clone(StandardShirt)
	
	for i,v in pairs(ClonedShirt) do
		Player.Character.Humanoid:AddAccessory(v)
	end
end)

I also had something setting the StandardShirt.Archivable = true, but I can’t remember why I wrote that in. Once I removed it, everything worked once before just breaking.

You are only cloning the table that references the shirt parts, not cloning the parts themselves. That’s why it only works once, it’s still using the original shirt parts and not cloning the parts individually. This revised code should work:

local StandardShirt = {ClothingFolderEly:WaitForChild("ElyStanCollar"), ClothingFolderEly:WaitForChild("ElyStanShirt"), ClothingFolderEly:WaitForChild("ElyStanPantsWaist"),
	ClothingFolderEly:WaitForChild("ElyStanRSleeve"), ClothingFolderEly:WaitForChild("ElyStanLSleeve"), ClothingFolderEly:WaitForChild("ElyStanLShoulder"), 
	ClothingFolderEly:WaitForChild("ElyStanRShoulder")}

GiveClothingEvent.OnServerEvent:Connect(function(Player)
	for i,v in pairs(StandardShirt) do
		Player.Character.Humanoid:AddAccessory(v:Clone())
	end
end)
1 Like

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