I have been working on a RNG game for about a Month now but there is one thing i tried to add but kept on failing
This is my Randomizer Script which i found Online i want to have Potions and Events in the Game where you get for example like 2X luck but i have no idea how to add a Luck System to this i tried looking online for solutions and found many Solutions but i have no idea how to add it if anyone is able to help me out on this it would be very appreciated
This is the Module Script where it gets the Gears from
i tried it out and somehow if i roll with like / 1000000 it doesnt give me the rarest gears it only gives me Witches Brew which is 1 / 55 there are 2 more gears beyond that one is 1 / 60 the other 1 / 55m it should give that but somehow it wont
oh and here is the non image code:
function GetRandomItem()
local Sum = 0
for GearName,Chance in pairs(items) do
Sum += Chance
end
local randomNumber = math.random(Sum)
for GearName,Chance in pairs(items) do
if randomNumber <= Chance * globalluckmultiplier then
return GearName
else
randomNumber -= Chance * globalluckmultiplier
end
end
end
sure! i didnt know you can do that im not posting that much on the dev forum
local items = require(game.ReplicatedStorage.Gears)
function GetRandomItem()
local Sum = 0
for GearName,Chance in pairs(items) do
Sum += Chance
end
local randomNumber = math.random(Sum)
for GearName,Chance in pairs(items) do
if randomNumber <= Chance then
return GearName
else
randomNumber -= Chance
end
end
end
math.random can output ONLY full numbers - 1, 2, 3, 4, …, 10000000. But not decimals. That’s the reason why Illumina will never be outputted (only possible situation if math.random will output epic combo after which illumina will be greated with matching combo of dictionary selections - in your case zero or 100, and ontop of that it needs to be selected as first/last dictionary value respectively)
What about luck - there’s 3 main ways to do it.
Manually adjust odds for every additional stat possible.
Use non-linear functions and adjust them:
local Sum = SumOfYourGears --(100 for example)
local ExtraLuck = Effect --(0.75 for example)
local Rng = math.random(Sum)^ExtraLuck --[==[ not true formula, only for
describing what I meant. Real one will be much more complicated.--]==]
Use reroll system, where each 1 point of luck = one reroll. Rarest selected item is outputted. For decimal luck, make reroll having chance too - 0.5 luck = 50% of reroll.
round all numbers in the table to 2 decimal places, then change the code to make up for it. adding x100 should do it.
local items = require(game.ReplicatedStorage.Gears)
function GetRandomItem()
local Sum = 0
for GearName,Chance in pairs(items) do
Sum += Chance*100
end
local randomNumber = math.random(Sum)
for GearName,Chance in pairs(items) do
local multchance = Chance*100
if randomNumber <= multchance then
return GearName
else
randomNumber -= multchance
end
end
end