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

How can one have 3 things spawn randomly but each are different in spawn rate?

This is not for my purposes... this is for everybody who wants to know how to do this, since this is something I have always wondered about..

The question is: How can you spawn 3 items randomly but have them all spawn at different rates. Such as spawning by rank(Common, Uncommon, Rare, etc.).

So I have no idea how you would do this, but I was thinking of doing it by percentages but I wouldn't even know how to start, so I don't even know if that would be possible...

Again this isn't for me and my purposes, I am asking for everybody who wants to know.

2 answers

✓ Accepted answer

Hello, Your idea on percentage is correct and can be done by integrating it with math.random so we can do it like this

local x = math.random(100)
if x < 21 then
print("I have a 20 percent chance to be spawned")
else if x < 51 then
print("I spawn 30 percent of the time ")
else 
print("The remaining percentage is conquered by me (50 percent)")

Hope this answers

1 comment

0

Oh Wow! That is so simple and yet exactly what I was asking about! Thank you for your contribution!

You could use math.random to generate a percentage like so...

local x = math.random(1,100)

if x <= 5 then					-- 5/100 chance to spawn (5% chance)
	print 'spawn rare'
elseif x <= 40 then				-- 40/100 chance to spawn (40% chance)
	print 'spawn uncommon'
else
	print 'spawn common'		-- defaults to common
end

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