:AddAccessory not working

I was making an accessory shop and i had made my own accessory.
I want to equip that accessory.
I decided to clone the accessory. here’s the code

script.Parent.MouseButton1Click:Connect(function()
	local skirt = game.ReplicatedStorage["Classic Lolita Skirt"]
	local copy = skirt:Clone()
	copy.Parent = game.ReplicatedStorage
	copy.Name = "ClassicSkirt"
	local event = game.ReplicatedStorage.Remotes.ClassicBuy
	local skirt = game.ReplicatedStorage:WaitForChild("ClassicSkirt")
	event:FireServer(skirt)
end)

and in the serverscriptservice

repstorage = game.ReplicatedStorage
Event = repstorage.Remotes:WaitForChild("ClassicBuy")
Event.OnServerEvent:Connect(function(Plr, copy)
	local Character = Plr.Character
	local Name = Character.Name
	if not Character:FindFirstChild(Name) then
		local humanoid = Character:FindFirstChild("Humanoid")
		humanoid:AddAccessory(copy)
	else
		print("AldreadyEquipped")
	end
	
end)

I saw the skirt cloned in repstorage
but when i press the button, it shows this

  09:24:51.722 - AddAccessory should be passed a valid Accessory object.
09:24:51.725 - Stack Begin
09:24:51.725 - Script 'ServerScriptService.Script', Line 8
09:24:51.725 - Stack End

Do kindly help me.

2 Likes

The problem is that when you pass copy from the client to the server, it becomes nil. This is because objects created on the client are only available on that client, since they don’t replicate to the server.

Try cloning the skirt on the server, and then calling AddAccesory, and see if that fixes the issue.

2 Likes

Ohhhh thanks a lot. That was kinda silly of me.
I didnt think about that.

1 Like

It’s a easy overlook. Especially since it didn’t use to be this way until FilteringEnabled was released.

1 Like