Hello,
I made a rarity system script, but I don’t know if it’s that good
Is there a simpler/better way?
Here’s the script.
- Are there any improvements or optimizations I can make?
- Is there a more efficient way to do this?
- Any tips on best practices for this type of script?
local RARITY_TABLE = {
{VALUE = "Nothing?", RARTIY = 1},
{VALUE = "Water", RARTIY = 2},
{VALUE = "Food", RARTIY = 3},
{VALUE = "Woah, thats rare!", RARTIY = 0.2},
}
function create_Rarity()
local TOTAL_RARITY = 0
for _, v in pairs(RARITY_TABLE) do
TOTAL_RARITY = TOTAL_RARITY + v.RARTIY
end
local RETURNED_VALUE = 0
local RANDOM_VALUE = TOTAL_RARITY * math.random()
for _, v in pairs(RARITY_TABLE) do
RETURNED_VALUE = RETURNED_VALUE + v.RARTIY
if RETURNED_VALUE >= RANDOM_VALUE then
return v.VALUE
end
end
end
while task.wait(0.1) do
local VALUE = create_Rarity()
print(VALUE)
end