First of all, hello.
I want to make a percentege system for my game, the problem? I can’t figure out how to make it.
Example on what i want to do:
Loot1: 25%
Loot2: 50%
Loot3 = 30%
Loot4 = 10%
Thanks for reading.
First of all, hello.
I want to make a percentege system for my game, the problem? I can’t figure out how to make it.
Example on what i want to do:
Loot1: 25%
Loot2: 50%
Loot3 = 30%
Loot4 = 10%
Thanks for reading.
U could use math.random(x, y)
for example. 25% = (1, 4) . 50% = (1, 2) You would want the function to find the number 1.
The solution here should help you.
How do i make a chance system? - Help and Feedback / Scripting Support - DevForum | Roblox
i dont think math.random would be a good option because It’s completly random ut i will try it, thanks
math.random would be a good option, and I have helped making loot tables before, but here’s an example:
local loottable = {
Loot1 = 25,
Loot2 = 25,
Loot3 = 30,
Loot4 = 10
}
local totalrarity = 0
for i,v in pairs(loottable) do totalrarity += v end
function getloot()
local lootnum = math.random(totalrarity)
local currentrarity = 0
for i,v in pairs(loottable) do
currentrarity += v
if lootnum <= currentrarity then return i end
end
end
print(getloot())
Now, there are multiple other ways to make the table, but this is just one going based off of how you provided the loot system.
Thanks, this is perfect, I’m using that system
Would the number values in the loottable translate directly to the percentage chance that the loot item will be picked?
The translate as a percentage of the whole. You can think of every number in the pot a ticket that each item has and you draw a ticket and check what item the ticket you pulled out pointed to.
So for the example
Loot1 has 25 tickets
Loot2 has 25 tickets
Loot3 has 30 tickets
Loot4 has 10 tickets.
Total tickets = 25+25+30+10 = 90
So each item has ticketCount/90 percent change of being selected.
So for example Loot1 has 25 tickets so the chance is 25/90=27.7778%
So I could have all of the values add up to 100 that would directly translate to a percentage? Or a value that would add up to a thousand for more precise percentage?
What I’m trying to say is that if I had values like:
Loot1 has 30 tickets
Loot2 has 60 tickets
Loot3 has 10 tickets
Total tickets = 100
This would then make Loot3 have a 10% chance of being selected?
Yes, That is correct. (Message length)