Script works in studio, not roblox game

Basically, in the title, the script works in Roblox studio, just not on the game
it removes accessories then add’s new ones


local Avatar = game.Workspace.Character.MainAvatar

script.Parent.MouseButton1Click:Connect(function()
	local descendants = Avatar:GetDescendants()
	for _, descendant in pairs(descendants) do
		if descendant:IsA("Accessory") then
			descendant:Destroy()
		end
	end
	local accessories = script:GetDescendants()
	for _, descendant1 in pairs(accessories) do
		if descendant1:IsA("Accessory") then
			local main = descendant1:Clone()
			Avatar.Humanoid:AddAccessory(main)
		end
	end

end)
2 Likes

Isn’t the Character a child of a Player in the workspace in game?

What is MainAvatar in rhe character?

image
it is a separate avatar