AddAccessory Not Working Properly

I’m working on a formal photo game where the player joins, their character is cloned, and put in front of a backdrop for a formal picture. By default, I add a silver duty belt as an accessory to their avatar. I also gave the player two buttons so they could change between various belts.

The problem is that after the first default accessory is added, I cannot add more accessories (even if the default is destroyed).

I attached a video below, and the code for more context on the issue I’m facing.

Video

Code

local player = game.Players.LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("cameraPosition")

local beltCustomizer = player.PlayerGui:WaitForChild("BeltCustomizer")
local currentBelt = beltCustomizer.Frame.CurrentBelt

event.OnClientEvent:Connect(function()
	local part = workspace:WaitForChild("CameraPart")
	local camera = workspace.CurrentCamera
	local character = player.Character or player.CharacterAdded:Wait()

	character.Archivable = true
	local clone = character:Clone()
	character.Archivable = false

	clone.Parent = workspace
	clone.HumanoidRootPart.CFrame = workspace:WaitForChild("characterPosition").CFrame
	clone.PrimaryPart = clone.HumanoidRootPart
	clone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

	local originalCFrame = clone.PrimaryPart.CFrame
	local rotation = CFrame.Angles(0, math.rad(-30), 0)
	clone:PivotTo(originalCFrame * rotation)

	local belt = game:GetService("ReplicatedStorage"):FindFirstChild("Silver Belt"):Clone()
	clone.Humanoid:AddAccessory(belt)

	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part.CFrame
	camera.FieldOfView = 30

	beltCustomizer.Frame.Gold.MouseButton1Click:Connect(function()
		currentBelt.Value.UIStroke.Parent = beltCustomizer.Frame.Gold
		currentBelt.Value = beltCustomizer.Frame.Gold
		clone:FindFirstChild("Silver Belt"):Destroy()
		if (not clone:FindFirstChild("Silver Belt")) then
			local newClone = game:GetService("ReplicatedStorage"):FindFirstChild("Gold Belt"):Clone()
			clone.Humanoid:AddAccessory(newClone)
		end
	end)
	beltCustomizer.Frame.Silver.MouseButton1Click:Connect(function()
		currentBelt.Value.UIStroke.Parent = beltCustomizer.Frame.Silver
		currentBelt.Value = beltCustomizer.Frame.Silver
		clone:FindFirstChild("Gold Belt"):Destroy()
		if (not clone:FindFirstChild("Gold Belt")) then
			local newClone = game:GetService("ReplicatedStorage"):FindFirstChild("Silver Belt"):Clone()
			clone.Humanoid:AddAccessory(newClone)
		end
	end)
end)

Cheers to anyone that can help!

1 Like

Just to add, the belts are correctly being cloned but they aren’t being placed on the character correctly. Could be a positioning issue but I’m not sure how to fix it or what the best approach would be.

It’s very possible that the other accessories aren’t set up properly, so Roblox doesn’t know where to position them.

A good way to test this is to just parent the accessory to the character model. If that doesn’t work, then yeah, something is wrong with the accessory.

Some things to check:

  • Is the part inside the accessory named “Handle”?
  • Is Handle unanchored?
  • Does Handle have an attachment inside of it matching another inside the rig?
  • Is your Handle welded to something else? If so, unweld it.

Hey @iGottic ! Thank you for the great explanation and for giving me some possible solutions to the issue. I checked both accessories (Silver and Gold belt) and everything seems to be as it should based on your checklist. The silver belt is added correctly when the player first triggers the RemoteEvent, but it will not add the second time. The gold belt doesn’t work at all. It’s as though the entire system just stops working after adding the accessory the first time.

I don’t think the accessories in question are configured incorrectly (or at least the silver belt) because the belt is added correctly the first time. It just won’t work if I try using the buttons.

To my knowledge, accessories aren’t supposed to be added on the client side, at least, it never worked for me.

Therefore, I suggest cloning the character on the server side and adding accessories using Humanoid:AddAccessory() or setting Accessory.Parent = Character on the server side as well. This will ensure everything works properly without having to find a tricky client-side workaround.


Capture

Have you tried this? It might solve the issue.

It appears I may have solved the issue (somehow) using this as the best guide, and @iGottic’s suggestion to parent the accessory directly to the character model. What I did was delete the clone and make a new clone of the character, but instead, I added the correct accessory. This positions the accessory correctly. I’m not sure what the logic behind this was but it works.

2 Likes

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