Setting three images to be a players accessories

for _, button in pairs(AccessoryBar:GetChildren()) do
	if button:IsA('ImageButton') then
		button.Visible = false
		button.Name = 'Empty'
		button.Icon.Image = ''
	end
end
						
for _, v in pairs(Dummy:GetChildren()) do
	if v:IsA('Accessory') then
    	if string.sub(v.Name, 1, 6) == 'Hat - ' then
			for _, button in next, AccessoryBar:GetChildren() do
				if button:IsA('ImageButton') then
			    	button.Name = string.sub(v.Name, 7)
					button.Icon.Image = 'https://www.roblox.com/asset-thumbnail/image?assetId=' .. string.sub(v.Name, 7) .. '&width=420&height=420&format=png'
					button.Visible = true
			    end
			end
		end
	end
end

Atm it just sets all 3 icons to be one of the accessories, not all 3


(bottom right buttons) should display one of each of the players accessories. Another problem is if I only have 2 accessories equipped, it stills shows all 3 buttons as visible.

You could try adding an UIListLayout to the AccessoryBar and cloning a button for each accessory:

local AccessoryButton = ...

for _, v in pairs(Dummy:GetChildren()) do
	if v:IsA('Accessory') then
    	if string.sub(v.Name, 1, 6) == 'Hat - ' then
			local NewAccessoryButton = AccessoryButton:Clone()
			NewAccessoryButton.Name = string.sub(v.Name, 7)
			NewAccessoryButton.Icon.Image = 'https://www.roblox.com/asset-thumbnail/image?assetId=' .. string.sub(v.Name, 7) .. '&width=420&height=420&format=png'
			NewAccessoryButton.Visible = true
            NewAccessoryButton.Parent = AccessoryBar
		end
	end
end

You could have a Boolean or int value for each accessory. Use the Changed Event (not sure what it is but I was told they have a changed event) so when you change the value to true or 1 or whatever, it triggers the code and that clones or removes the accessory plus changes the gui.