I’m wondering if there is something I can use that would do something similar to math.random() but would not go over a set value (“Capacity Storage System”)
Example:
Player gets a random number eg: (1,5) and adds to a total 1-5/30
Max the number can go to is 30 nothing more.
Well math.random() has two parameters, the minimum value and the maximum value. Just put the maximum value as the second parameter when you call the function
Let me give a realistic example of what I’m trying to do here:
You kill an NPC and receive 1,5 Cash and it gets added to a Storage UI with a Capacity of (“30”) it must not go over 30 and a simple math.random(1,30) will not work as that would be far to easy to reach maximum capacity.
Because they want it so math.random(1,5) happens several times and adds to a cumulative total, which is 30. That’s different than just math.random(1,30).
local total_number = 0
-- then when ever you want to add a number
total_number += math.random(1,5)
if total_number >= 30 then
total_number = 30
end
-- I mean this is very basic but it does the job, if you want you can make it fancier