Equipping faces and hats getting error

Hey, I’m currently making a mannequin system where players can purchase or try on stuff from a mannequin, but im having a small issue: when im equipping hats, it works perfectly fine, but when im equipping faces, it gives me an error. these are my scripts:

where trysingle is being fired:

			if try and try:IsA("TextButton") then
				try.Activated:Connect(function()
					local selectedHatID = v.Name
					local selectedFaceID = "" -- Initialize selectedFaceID
					if desc.Face and tonumber(desc.Face) and tonumber(desc.Face) > 0 then
						selectedFaceID = desc.Face -- Get the faceID from the HumanoidDescription if it exists
					end
					game.ReplicatedStorage.trySingle:FireServer(selectedHatID, selectedFaceID)
				end)
			end

where the error is occuring (tryon script):

game.ReplicatedStorage.trySingle.OnServerEvent:Connect(function(player, itemID, faceID)
	if not debounce[player.UserId] then
		local desc = player.Character.Humanoid:GetAppliedDescription()

		-- Append the new item to the existing accessories list for HatAccessory
		if itemID and tonumber(itemID) then
			if desc.HatAccessory == "" then
				desc.HatAccessory = itemID
			else
				desc.HatAccessory = desc.HatAccessory .. "," .. itemID
			end
		end

		-- Set the face to the new faceID if it's valid
		if faceID and tonumber(faceID) then
			desc.Face = faceID
		end

		player.Character.Humanoid:ApplyDescription(desc)
		debounce[player.UserId] = true
		wait(1)
		debounce[player.UserId] = nil
	end
end)

what the error is:
image

The error you are getting is because you have the same asset in one of the properties in the HumanoidDescription, this will happen if the user already has the face on you are trying to give them.

are you sure? btw, there is another issue, when i equip a hat from a mannequin with a face in it, it’ll equip the hat and the face for some reasons? it doesnt do that when theres only hats in the mannequin, and it only equips the selected accessory properly

Maybe try removing the property where you are applying the asset, example if the hats has rbxasset:/1 then set it to nothing and then add the asset you want.

quite confused, how would i do that specifically? would it fix the issues im experiencing?

I am not exactly sure, I have never done something like you are doing right now but I will try and help you, I believe it could fix your problem.

I can possibly send the important parts from both scripts, as it may contain useful stuff (?)

this is where the tryon is being fired and where the buttons are being created:

game:GetService("ReplicatedStorage").productList.OnClientEvent:Connect(function(model)
	tryon = model

	-- Reset the total cost and accessoryCosts when a new model is loaded
	accessoryCosts = {}

	local humanoid = model:WaitForChild("Humanoid")
	local desc = humanoid.HumanoidDescription

	local hats = string.split(desc.HatAccessory, ",")
	local faceaccessory = string.split(desc.FaceAccessory, ",")
	local waist = string.split(desc.WaistAccessory, ",")
	local hair = string.split(desc.HairAccessory, ",")
	local front = string.split(desc.FrontAccessory, ",")
	local back = string.split(desc.BackAccessory, ",")
	local neck = string.split(desc.NeckAccessory, ",")
	local shoulders = string.split(desc.ShouldersAccessory, ",")

	script.Parent.Items.ScrollingFrame.CanvasPosition = Vector2.new(0, 0)

	-- Remove existing buttons
	for _, v in ipairs(script.Parent.Items.ScrollingFrame:GetChildren()) do
		if v:IsA("ImageButton") then
			v:Destroy()
		end
	end

	-- Create buttons for each accessory type
	createButtons(hats, "hats")
	createButtons(faceaccessory, "faceaccessory")
	createButtons(waist, "waist")
	createButtons(hair, "hair")
	createButtons(front, "front")
	createButtons(back, "back")
	createButtons(neck, "neck")
	createButtons(shoulders, "shoulders")

	-- Create buttons for special accessories
	if desc.Face and tonumber(desc.Face) and tonumber(desc.Face) > 0 then
		createButton(desc.Face, "face")
	end

	if desc.Shirt and tonumber(desc.Shirt) and tonumber(desc.Shirt) > 0 then
		createButton(desc.Shirt, "shirt")
	end

	if desc.Pants and tonumber(desc.Pants) and tonumber(desc.Pants) > 0 then
		createButton(desc.Pants, "pants")
	end

	if desc.GraphicTShirt and tonumber(desc.GraphicTShirt) and tonumber(desc.GraphicTShirt) > 0 then
		createButton(desc.GraphicTShirt, "tshirt")
	end

	sound:Play()

	for _, v in ipairs(script.Parent.Items.ScrollingFrame:GetChildren()) do
		if v:IsA("ImageButton") then
			local buy = v.Frame.Buy
			if buy and buy:IsA("TextButton") then
				buy.Activated:Connect(function()
					mps:PromptPurchase(player, v.Name)
				end)
			end

			local try = v.Frame.Try
			if try and try:IsA("TextButton") then
				try.Activated:Connect(function()
					local selectedHatID = v.Name
					local selectedFaceID = "" -- Initialize selectedFaceID
					if desc.Face and tonumber(desc.Face) and tonumber(desc.Face) > 0 then
						selectedFaceID = desc.Face -- Get the faceID from the HumanoidDescription if it exists
					end
					game.ReplicatedStorage.trySingle:FireServer(selectedHatID, selectedFaceID)
				end)
			end

			v.Activated:Connect(function()
				for _, child in ipairs(script.Parent.Items.ScrollingFrame:GetChildren()) do
					if child:IsA("ImageButton") and child.Frame then
						child.Frame.Visible = false
					end
				end
				v.Frame.Visible = true
			end)
		end
	end

	-- Trigger the tween animation to show the frame
	local ItemsFrame = player.PlayerGui:WaitForChild("ScreenGui").ItemsFrame
	triggerTweenAnimation(ItemsFrame, UDim2.new(0.865, 0, 0.5, 0), UDim2.new(0.235, 0, 0.560, 0))
end)

and this is my full tryon script, you can see from the productlist thats being fired that i have another button that equips everything from that mannequin, including faces:

local debounce = {}

game.ReplicatedStorage.productList.OnServerEvent:Connect(function(player, serial)
	if not debounce[player.UserId] then
		local desc = player.Character.Humanoid:GetAppliedDescription()
		local mannequinDesc = serial.Humanoid.HumanoidDescription

		-- Append the new hat to the existing accessories list
		if mannequinDesc.HatAccessory then
			if desc.HatAccessory == "" then
				desc.HatAccessory = mannequinDesc.HatAccessory
			else
				desc.HatAccessory = desc.HatAccessory .. "," .. mannequinDesc.HatAccessory
			end
		end
		if mannequinDesc.FaceAccessory then
			if desc.FaceAccessory == "" then
				desc.FaceAccessory = mannequinDesc.FaceAccessory
			else
				desc.FaceAccessory = desc.FaceAccessory .. "," .. mannequinDesc.FaceAccessory
			end
		end
		if mannequinDesc.BackAccessory then
			if desc.BackAccessory == "" then
				desc.BackAccessory = mannequinDesc.BackAccessory
			else
				desc.BackAccessory = desc.BackAccessory .. "," .. mannequinDesc.BackAccessory
			end
		end

		if mannequinDesc.Face ~= 0 then
			desc.Face = mannequinDesc.Face
		end

		if mannequinDesc.Shirt ~= 0 then
			desc.Shirt = mannequinDesc.Shirt
		end

		if mannequinDesc.Pants ~= 0 then
			desc.Pants = mannequinDesc.Pants
		end

		if mannequinDesc.GraphicTShirt ~= 0 then
			desc.GraphicTShirt = mannequinDesc.GraphicTShirt
		end

		player.Character:FindFirstChild("Humanoid"):ApplyDescription(desc)
		debounce[player.UserId] = true
		wait(1)
		debounce[player.UserId] = nil
	end
end)

game.ReplicatedStorage.trySingle.OnServerEvent:Connect(function(player, itemID, faceID)
	if not debounce[player.UserId] then
		local desc = player.Character.Humanoid:GetAppliedDescription()

		-- Append the new item to the existing accessories list for HatAccessory
		if itemID and tonumber(itemID) then
			if desc.HatAccessory == "" then
				desc.HatAccessory = itemID
			else
				desc.HatAccessory = desc.HatAccessory .. "," .. itemID
			end
		end

		-- Set the face to the new faceID if it's valid
		if faceID and tonumber(faceID) then
			desc.Face = faceID
		end

		player.Character.Humanoid:ApplyDescription(desc)
		debounce[player.UserId] = true
		wait(1)
		debounce[player.UserId] = nil
	end
end)

Send all of those variables in a table, then set the new description to the data in the table but change the values you need to because it should be way more simple and easy to tell what the issue is.

Ive changed it to a table, but i don’t really know how to exactly do the rest, ive recently started learning coding, i can show some other parts from this script aswell, but it may not be as useful:

I’m still available if someone’s down to help :slight_smile:

1 Like