How would you go about doing this in lua? To make it simple, this is an example of a random player selection.
local p = game.Players:GetPlayers()
local rnd = math.random(1,#p)
print (p[rnd].Name)
How can I make a percentage based for each player but as an array? For example, Dave has 15% chance of being selected, Steve has 65% chance of being selected, Bert has 20% chance of being selected.
My run at it:
local percent = {0.15, 0.65,0.2}
local player = {"Dave", "Steve", "Bert"}
local select
local total = 0
for i = 1, #percent do
total = total + percent[i]
end
local rnd = math.random(1,100)/100
print(rnd)
for j = 1, #percent do
local prev = percent[j-1] or 0
print(prev)
if prev >= rnd and rnd <= percent[j] then
select = player[j]
break;
end
end
print(select)
EDIT: Modified code above, doesn't work accordingly :P

1 comment
right now this post has 0 upvotes, kinda new, I still don't understand how this works, can you explain more?