Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can I use math.random for a crate system?

I have made a script that when a button is pressed (for testing purposes) it generates a random number between 1 and 100 and then identifies it, is this a fair way to make a system like this as if the number is random each has a 1 in 100 chance of being pulled?, i was wondering as why do games use percentage if they could do this? Many regards, THELFCMAN

script.Parent.MouseButton1Click:Connect(function()
---- This is going to be the math.random to get a number between 1 to 100, each is different raritites
local number = math.random(1, 100)
print(number)
if number <60 then --- Common
	print("Common")
elseif number == 61 or number >60 and number<85 then print("Uncommon")
elseif number == 85 or number >85 and number<95 then print("Rare")
elseif number == 95 or number >95  then print("Legendary")
	end
	end)

2 comments

0

im gonna add a mythical too lol, like 0.5% chance

0

Not sure what you mean by "why do games use percentage if they could do this", that is what your doing just with a diffrent number format.

1 answer

✓ Accepted answer

There isn't really a better way to this on Roblox. I think the way you are using is good except you might want to consider using elseif to make your expression/conditions shorter.

1 comment

0

Thank you!, the problem i was facing was that i was looking at pet free models and saw massive scripts just for percentages and i was confused. I am still pretty new to scripting and being correct is an achievement! thanks for your time

This discussion is preserved as it was. New answers, comments, and votes are closed.