Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add a drop rate (chance to get item) from mobs in my RPG?

Asked by
flanfy -3
6 years ago

I am newish to scripting and would love to know how to do this with math.random, for example, you have a chance at getting the Holy Blade from killing this mob.

0
doing something like if math.random(1,10) == 1 then comes to mind little5 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You want to create a variable for math.random(). Then the function will choose a random number between the given 1st value and 2nd value. Then the variable will be equal to that selected number.

Chance = math.random(1, 10)
if Chance == 1 then
    --Drop Holy Blade
end

You can of course change the values and variable.

Or you can do:

if math.random(1, 10) == 1 then
    --Drop Holy Blade
end
0
also use math.randomseed() at the beginning lines of your code as normal math.random is not exactly random, there's an article on this: https://www.robloxdev.com/articles/Random-Number-Generation HilyrHere 79 — 6y
Ad

Answer this question