Adding/removing Accessories

The Accessory documentation on the wiki is not up to par.

Here’s what my accessory looks like:
image

In my code, pickaxeHandle points to the Pickaxe Accessory.
I want to “equip” it using

pickaxeHandle.Parent = char;
hum:AddAccessory(pickaxeHandle);

and unequip it using

pickaxeHandle.Parent = script;

Now when I equip it, it gives me a “AddAcessory failed: Accessory is already being worn by another character” warning. And the pickaxe handle floats around at the position it is before it’s parented to my character. My character’s RightGripAttachment exists.

7 Likes

Can’t confirm, but with tools the Equip function handles the parenting of the tool object.

Try using AddAccessory without parenting it.

I’d guess that since it’s already parented it thinks it’s on a character already, but I’m on mobile so I can’t verify.

1 Like

I just tried that. I’m not getting the warning anymore but I’m getting the same problem of the handle not actually welding to my character.

1 Like

Is “pickaxeHandle” the actual handle or the accessory instance itself? Make sure you’re passing the accessory, not the handle.

1 Like

It’s the accessory itself.

1 Like
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		char:WaitForChild('Humanoid'):AddAccessory(game.ReplicatedStorage.ClassyTophat)
	end)
end)

The above code worked just fine for adding the accessory and had no issues of the handle floating around beforehand.
Where is your script parented and when do you need to add the accessory?

2 Likes

The script is running on the client. It might be broken because it’s not running on the server. I would expect AddAccessory to create a weld on the client only when called from the client.

1 Like

Aha, that’s the issue. Welds are created on the server, so if done from the client, it doesn’t actually weld iirc. I’ve done work like this before on an avatar editor and had to come up with some make-shift method for locally-welding the accessories.

If you make it server-side, that should fix your problems! :smiley:

1 Like

I tried putting the accessory on in the server via the command line and it’s still broken. And if I’m calling AddAccessory from the client, the correct behavior would be to create a weld on the client. Why are Accessories so awful to work with? :neutral_face:

1 Like

I too wish if called on client-side that local welds would work, but unfortunately that’s not the case.

Does it work with the code I supplied? Also, where is the accessory originally parented?

1 Like

Try just parenting the accessory rather than using :AddAccessory, they’re essentially the same.

1 Like

The pickaxe accessory is coming from my client. The intended behavior is to get the pickaxe welded to my character at the right attachment on the client side. Neither AddAccessory nor parenting it to the character nor both works.

1 Like

Is there a reason you’re specifically wanting this done on the client-side? If the accessory is created locally and FE is enabled, it’ll only exist on that client.

If you could put the accessory in ReplicatedStorage, both client and server can access it and you’ll be able to handle AddAccesory on the server as well as any Parenting that you want the server to see.

If you could explain what you’re using this all for, I could better assist you. :slight_smile:

1 Like

The wiki is 403-ing for me so I can not actually verify, but I thought AddAccessory handles attachments properly while parenting messes that up.

@TaaRt There’s no documentation for that, which is one of the reasons I said the wiki documentation on this is lacking.

@CodeSleepRepeat I just tried putting the accessory in ReplicatedStorage and then adding it from there on the client. Same problem as when it was in PlayerScripts. I need to call AddAccessory on the client side because I want the pickaxe to show up on my character immediately when I equip it (instead of waiting ~.1 seconds because of latency). What we’ve found is a bug so I made a bug report here:

1 Like

Unfortunately, they’re probably going to say this is currently the expected-behavior when attempting to call AddAccessory or Parent the instance from client-side. I believe I saw a post about that on here previously.

With the avatar editor I worked on, I didn’t experience any substantial latency. Seemed to me like everything always loaded quickly.

Is this in a shop of sorts? How are you determining when to add the accessory?

1 Like

I made a tool system that functions just like the default one. The pickaxe is one of the tools, so I want it to show up immediately when I select the tool. If there is already code in Humanoid that welds an accessory to the character, I don’t see why it wouldn’t run on the client. I’d count that as a bug.

1 Like

I found the work-around TheGamer101 wrote. That should be the fix you’re looking for. Yeah, you’d think you’d be able to either Parent or call AddAccessory from the client and it’d create the welds and all that good stuff, but until then it requires the work-around.

Hope that fixes your problem!

8 Likes

Thank you :smiley:

2 Likes