Make Hair select random

So I made a script to copy hats from a specific folder but I want to make Hair be chosen randomly. This is my script:

function TransformModule.AddHair(Char)
	local Transformed = Char:FindFirstChild("Transformed")
	local PlayerType = Transformed.Type
	local Folder = script.Accesories
	for _, v in pairs (Folder:GetChildren())do
		if v.Name == PlayerType.value then
			if v:FindFirstChild("Hair") then
				local FClone = v:FindFirstChild("Hair")
				for _,v in ipairs(FClone:GetChildren()) do
					local Clone = v:Clone()
					Clone.Parent = Char
					Clone:FindFirstChild("Handle").Anchored = false
					local TransparencyInfo =
					local Trantween = game:GetService("TweenService"):Create(Clone:FindFirstChild("Handle"),TransparencyInfo,{Transparency = 0})
					Clone:FindFirstChild("Handle").Color = Transformed:FindFirstChild("Color").Value


You could make an array with the hairs and pick a random number, like this:

local Hairs = {
    Hair1 = Folder.Hair1, --Index number 1
    Hair2 = Folder.Hair2, --Index number 2

-- Or this

local Hairs = HairsFolder:GetChildren()

-- And then to pick a random one in the array:

local RandomlyPickedHair = Hairs[math.random(1,#Hairs)]
1 Like

How would I place it into the Player Char?

If the hair is an accesory, you can just parent them to the Char and i believe they should glue to the head. If you’re supersticious, you can also do Humanoid:AddAccesory(YourAcessoryHere)

Oh I did that but it wouldt go to the player but I forgot to apply it in the main script.

Are the two functions you should be making use of.