--[[ 

--[Create a table containing some percentages, example table:

     local GuitarChances = {["Red"] = 50, ["Blue"] = 25, ["Green"] = 10}
     
     --you don't have to make the addition of the chances equal to 100, the script will auto-convert the chances.
     
  ]
  
--[Next Step, call the function and get the result! Example = 

        local GuitarChances = {["Red"] = 50, ["Blue"] = 25, ["Green"] = 10}
        
        local SelectedGuitarColor = Roll(GuitarChances)
        
        print(SelectedGuitarColor)
        
        (this script will print a random guitar color with the chances In the table.)
        
        
]

pls leave a like if you don't mind :D
]]


function Roll(Chances)
	local summary = 0

	for index, chance in pairs(Chances) do
		summary += chance
	end

	local NewChances = table.clone(Chances)

	for index, Chance in pairs(NewChances) do
		NewChances[index] = summary / (100 / Chance)
	end

	task.wait()

	local RandomNumber = math.random(summary)

	for index, chance in pairs(NewChances) do

		local Result = index

		local StartPoint, EndPoint = chance, 0

		for NextIndex, NextChance in pairs(NewChances) do
			if NextChance < chance  then
				StartPoint += NextChance; EndPoint += NextChance
			elseif NextChance == chance and NextIndex ~= index then
				StartPoint += NextChance

				local Set = math.random(1,2)

				if Set > 1 then
					Result = NextIndex
				end	
			end
		end

		if RandomNumber > EndPoint and RandomNumber <= StartPoint then

			return Result

		end

	end

end
