Give a random accesorie to character

Hello, im not that good at scripting, so i need help with this code :grinning::

  1. I want that a random accesory for a list i select of ID from catalog, equip in the player

Script:

local accessoryId = 4645440842 or 170892848 

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		local Hat = game:GetService("InsertService"):LoadAsset(math.random(accessoryId))

		local accessory = Hat 
		for i,v in pairs(accessory:GetChildren()) do
			if(v.ClassName == "Accessory")then
				Char.Humanoid:AddAccessory(v) 

				break
			end
			wait()
		end
	end)
end)

Please help me, and thanks for reading! :grinning:

Instead of this, do:

local Accessories = {4645440842,170892848}

This should work

Change it to:

local Hat = game:GetService("InsertService"):LoadAsset(math.random(1,#Accessories))

It would have to be

Accessories[math.random(1,#Accessories)]
1 Like

True. My bad, I am on mobile and it is annoying to type from there.

Same, I just copied and pasted what you put lmao.

yes It works! thank you so much :smiley:

Thank you so much for the help!!