I made a percentage randomizer for a extremely basic case opening system but every time the function picks a random object, it always goes for 2 when it should be 1 and its always rare and uncommon. never common. This is the script:
function buy()
local random_number = math.random(0, 100)
if random_number <= 0 then --70%
print("common")
end
if random_number < 70 then --25%
print("uncommon")
end
if random_number < 95 then --5%
print("rare")
end
end
script.Parent.MouseButton1Click:Connect(buy)
as you can see, very basic and very annoying why it does not work. no errors are found in the output
You are checking if random_number is less or equal to zero, which is a really low chance.
You would probably want to do something like this; Checking for greater than (>) rather than less than (<), and starting with the rarest and moving your way to the most common.
if random_number > 95 then --5%
print("rare")
elseif random_number > 70 then --25%
print("uncommon")
else
print("common")
end
oh, my mistake that explains the only rare and uncommon. I forgot to change the symbols as this script was part of another I had in the game but I still have doubled selection
edit: I added the “elseif” and “else” and this stopped the multiple selection. thanks for the help!