Need help with shortening and advancing RNG script

Hello fellow people!
I am trying to find out how I can shorten this RNG script and make so that I can add more types of “dimensions”. I also want to implement a luck based system for 2x, 3x, and so on…
Server Script recieving roll call:

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")

--//Remotes
local RollingSystemRemotes = RS:WaitForChild("Client").GameSystem.RollingSystem
local RolledRemote = RollingSystemRemotes.Rolled
local ReadRollTypesRemote = RollingSystemRemotes.ReadRollTypes

--//Modules
local RollTypes = require(script.RollTypesModule)
local ReadAndWriteData = require(game:GetService("ServerScriptService").Client.PlayerData.ReadAndWriteData)

--//Server Storage Data and
local PlayersDataFolder = SS:WaitForChild("PlayersData")

--//Functions
function AddPlayerStats(Player, RollTypeTable)
	local RollingData = PlayersDataFolder[Player.Name].RollingData

	for i, RollType in pairs(RollingData.RollTypes:GetChildren()) do
		if RollType.Name == RollTypeTable[1] then
			RollType.Value += 1
		end
	end
	RollingData.Rolls.Value += 1
	
	local StatsEarned = {}
	
	local XPEarned = RollTypeTable[4]*750
	local MoneyEarned = RollTypeTable[4]*1000
	table.insert(StatsEarned, XPEarned)
	table.insert(StatsEarned, MoneyEarned)
	
	ReadAndWriteData.AddXP(Player, XPEarned, false)
	ReadAndWriteData.AddMoney(Player, MoneyEarned, false)
	task.wait(0.1)
	local PlayerData = ReadAndWriteData.ReadData(Player)
	return StatsEarned, PlayerData
end

function CallRecieved(Player)
	local generated = Random.new():NextInteger(1, 274877906944)
	if generated <= 274877906944 and generated >= 137438953472 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Common Dimension"])
		return RollTypes["Common Dimension"], StatsEarned, PlayerData
	elseif generated <= 137438953472 and generated >= 68719476736 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Uncommon Dimension"])
		return RollTypes["Uncommon Dimension"], StatsEarned, PlayerData
	elseif generated <= 68719476736 and generated >= 34359738368 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Standard Dimension"])
		return RollTypes["Standard Dimension"], StatsEarned, PlayerData
	elseif generated <= 34359738368 and generated >= 17179869184 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Rare Dimension"])
		return RollTypes["Rare Dimension"], StatsEarned, PlayerData
	elseif generated <= 17179869184 and generated >= 8589934592 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Ultra Dimension"])
		return RollTypes["Ultra Dimension"], StatsEarned, PlayerData
	elseif generated <= 8589934592 and generated >= 4294967296 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Superior Dimension"])
		return RollTypes["Superior Dimension"], StatsEarned, PlayerData
	elseif generated <= 4294967296 and generated >= 2147483648 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Absolute Dimension"])
		return RollTypes["Absolute Dimension"], StatsEarned, PlayerData
	elseif generated <= 2147483648 and generated >= 1073741824 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Unleashed Dimension"])
		return RollTypes["Unleashed Dimension"], StatsEarned, PlayerData
	elseif generated <= 1073741824 and generated >= 536870912 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Lightning Dimension"])
		return RollTypes["Lightning Dimension"], StatsEarned, PlayerData
	elseif generated <= 536870912 and generated >= 268435456 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Matter Dimension"])
		return RollTypes["Matter Dimension"], StatsEarned, PlayerData
	elseif generated <= 268435456 and generated >= 134217728 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Starlight Dimension"])
		return RollTypes["Starlight Dimension"], StatsEarned, PlayerData
	elseif generated <= 134217728 and generated >= 67108864 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Star Dimension"])
		return RollTypes["Star Dimension"], StatsEarned, PlayerData
	elseif generated <= 67108864 and generated >= 33554432 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Nebula Dimension"])
		return RollTypes["Nebula Dimension"], StatsEarned, PlayerData
	elseif generated <= 33554432 and generated >= 16777216 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Light Nebula Dimension"])
		return RollTypes["Light Nebula Dimension"], StatsEarned, PlayerData
	elseif generated <= 16777216 and generated >= 8388608 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Dark Nebula Dimension"])
		return RollTypes["Dark Nebula Dimension"], StatsEarned, PlayerData
	elseif generated <= 8388608 and generated >= 4194304 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Absolute Nebula Dimension"])
		return RollTypes["Absolute Nebula Dimension"], StatsEarned, PlayerData
	elseif generated <= 4194304 and generated >= 2097152 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Super Nova Dimension"])
		return RollTypes["Super Nova Dimension"], StatsEarned, PlayerData
	elseif generated <= 2097152 and generated >= 1048576 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Hyper Nova Dimension"])
		return RollTypes["Hyper Nova Dimension"], StatsEarned, PlayerData
	elseif generated <= 1048576 and generated >= 524288 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Gamma Radiation Dimension"])
		return RollTypes["Gamma Radiation Dimension"], StatsEarned, PlayerData
	elseif generated <= 524288 and generated >= 262144 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Gamma Ray Dimension"])
		return RollTypes["Gamma Ray Dimension"], StatsEarned, PlayerData
	elseif generated <= 262144 and generated >= 131072 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Black Hole Dimension"])
		return RollTypes["Black Hole Dimension"], StatsEarned, PlayerData
	elseif generated <= 131072 and generated >= 65536 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Light Galaxy Dimension"])
		return RollTypes["Light Galaxy Dimension"], StatsEarned, PlayerData
	elseif generated <= 65536 and generated >= 32768 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Dark Galaxy Dimension"])
		return RollTypes["Dark Galaxy Dimension"], StatsEarned, PlayerData
	elseif generated <= 32768 and generated >= 16384 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Collection Dimension"])
		return RollTypes["Collection Dimension"], StatsEarned, PlayerData
	elseif generated <= 16384 and generated >= 8192 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Cluster Dimension"])
		return RollTypes["Cluster Dimension"], StatsEarned, PlayerData
	elseif generated <= 8192 and generated >= 4096 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Fourth Dimension"])
		return RollTypes["Fourth Dimension"], StatsEarned, PlayerData
	elseif generated <= 4096 and generated >= 2048 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Unidentified Dimension"])
		return RollTypes["Unidentified Dimension"], StatsEarned, PlayerData
	elseif generated <= 2048 and generated >= 1024 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Newfound Dimension"])
		return RollTypes["Newfound Dimension"], StatsEarned, PlayerData
	elseif generated <= 1024 and generated >= 512 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["LightVoid Dimension"])
		return RollTypes["LightVoid Dimension"], StatsEarned, PlayerData
	elseif generated <= 512 and generated >= 256 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["DarkVoid Dimension"])
		return RollTypes["DarkVoid Dimension"], StatsEarned, PlayerData
	elseif generated <= 256 and generated >= 128 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Void Dimension"])
		return RollTypes["Void Dimension"], StatsEarned, PlayerData
	elseif generated <= 128 and generated >= 64 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Quantum Dimension"])
		return RollTypes["Quantum Dimension"], StatsEarned, PlayerData
	elseif generated <= 64 and generated >= 32 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Infinity Dimension"])
		return RollTypes["Infinity Dimension"], StatsEarned, PlayerData
	elseif generated <= 32 and generated >= 16 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Multiverse Dimension"])
		return RollTypes["Multiverse Dimension"], StatsEarned, PlayerData
	elseif generated <= 16 and generated >= 8 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Meta Dimension"])
		return RollTypes["Meta Dimension"], StatsEarned, PlayerData
	elseif generated <= 8 and generated >= 4 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Meta Universe Dimension"])
		return RollTypes["Meta Universe Dimension"], StatsEarned, PlayerData
	elseif generated <= 4 and generated >= 2 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Dark Energy Dimension"])
		return RollTypes["Dark Energy Dimension"], StatsEarned, PlayerData
	elseif generated <= 2 and generated >= 1 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Dark Matter Dimension"])
		return RollTypes["Dark Matter Dimension"], StatsEarned, PlayerData
	elseif generated == 1 then
		local StatsEarned, PlayerData = AddPlayerStats(Player, RollTypes["Dimension Ruler"])
		return RollTypes.DimensionRuler
	end
end

function ReadRollTypes()
	local RollTypesTable = {}
	for i, RollType in pairs(RollTypes) do
		RollTypesTable[i] = RollType
	end
	return RollTypesTable
end

--//Connections
RolledRemote.OnServerInvoke = function(Player)
	return CallRecieved(Player)
end

ReadRollTypesRemote.OnServerInvoke = function(Player)
	return ReadRollTypes()
end

RollTypes Module:


local RollTypes = {}

RollTypes["Common Dimension"] = {"Common Dimension","1 in 2", Color3.fromRGB(255, 255, 255), 1}
RollTypes["Uncommon Dimension"] = {"Uncommon Dimension","1 in 4", Color3.fromRGB(125, 125, 125), 2}
RollTypes["Standard Dimension"] = {"Standard Dimension","1 in 8", Color3.fromRGB(255, 162, 162), 3}
RollTypes["Rare Dimension"] = {"Rare Dimension","1 in 16", Color3.fromRGB(93, 177, 255), 4}
RollTypes["Ultra Dimension"] = {"Ultra Dimension","1 in 32", Color3.fromRGB(255, 198, 28), 5}
RollTypes["Superior Dimension"] = {"Superior Dimension","1 in 64", Color3.fromRGB(135, 113, 2), 6}
RollTypes["Absolute Dimension"] = {"Absolute Dimension","1 in 128", Color3.fromRGB(21, 107, 57), 7}
RollTypes["Unleashed Dimension"] = {"Unleashed Dimension","1 in 256", Color3.fromRGB(91, 21, 108), 8}
RollTypes["Lightning Dimension"] = {"Lightning Dimension","1 in 512", Color3.fromRGB(0, 255, 238), 9}
RollTypes["Matter Dimension"] = {"Matter Dimension","1 in 1,024", Color3.fromRGB(181, 43, 128), 10}
RollTypes["Starlight Dimension"] = {"Starlight Dimension","1 in 2,048", Color3.fromRGB(255, 124, 58), 11}
RollTypes["Star Dimension"] = {"Star Dimension","1 in 4,096", Color3.fromRGB(255, 239, 14)}
RollTypes["Nebula Dimension"] = {"Nebula Dimension","1 in 8,192", Color3.fromRGB(136, 17, 255), 12}
RollTypes["Light Nebula Dimension"] = {"Light Nebula Dimension","1 in 16,384", Color3.fromRGB(107, 63, 124), 13}
RollTypes["Dark Nebula Dimension"] = {"Dark Nebula Dimension","1 in 32,768", Color3.fromRGB(35, 32, 45), 14}
RollTypes["Absolute Nebula Dimension"] = {"Absolute Nebula Dimension","1 in 65,536", Color3.fromRGB(165, 39, 255), 15}
RollTypes["Super Nova Dimension"] = {"Super Nova Dimension","1 in 131,072", Color3.fromRGB(52, 62, 255), 16}
RollTypes["Hyper Nova Dimension"] = {"Hyper Nova Dimension","1 in 262,144", Color3.fromRGB(43, 15, 255), 17}
RollTypes["Gamma Radiation Dimension"] = {"Gamma Radiation Dimension","1 in 524,288", Color3.fromRGB(183, 0, 255), 18}
RollTypes["Gamma Ray Dimension"] = {"Gamma Ray Dimension","1 in 512,000", Color3.fromRGB(255, 0, 98), 19}
RollTypes["Black Hole Dimension"] = {"Black Hole Dimension","1 in 1,048,576", Color3.fromRGB(30, 30, 30), 20}
RollTypes["Light Galaxy Dimension"] = {"Light Galaxy Dimension","1 in 2,097,152", Color3.fromRGB(52, 228, 255), 21}
RollTypes["Dark Galaxy Dimension"] = {"Dark Galaxy Dimension","1 in 4,194,304", Color3.fromRGB(29, 65, 58), 22}
RollTypes["Collection Dimension"] = {"Collection Dimension","1 in 8,388,608", Color3.fromRGB(255, 178, 247), 23}
RollTypes["Cluster Dimension"] = {"Cluster Dimension","1 in 16,777,216", Color3.fromRGB(255, 170, 186), 24}
RollTypes["Fourth Dimension"] = {"Fourth Dimension","1 in 33,554,432", Color3.fromRGB(249, 255, 130), 25}
RollTypes["Unidentified Dimension"] = {"Unidentified Dimension","1 in 67,108,864", Color3.fromRGB(35, 20, 21), 26}
RollTypes["Newfound Dimension"] = {"Newfound Dimension","1 in 134,217,728", Color3.fromRGB(1, 69, 255), 27}
RollTypes["Light Void Dimension"] =  {"Light Void Dimension","1 in 268,435,456", Color3.fromRGB(25, 25, 25), 28}
RollTypes["Dark Void Dimension"] = {"Dark Void Dimension","1 in 536,870,912", Color3.fromRGB(25, 25, 25), 29}
RollTypes["Void Dimension"] = {"Void Dimension","1 in 1,073,741,824", Color3.fromRGB(17, 15, 13), 30}
RollTypes["Quantum Dimension"] = {"Quantum Dimension","1 in 2,147,483,648", Color3.fromRGB(211, 255, 15), 31}
RollTypes["Infinity Dimension"] = {"Infinity Dimension","1 in 4,294,967,296", Color3.fromRGB(255, 247, 0), 32}
RollTypes["Multiverse Dimension"] = {"Multiverse Dimension","1 in 8,589,934,592", Color3.fromRGB(0, 255, 42), 33}
RollTypes["Meta Dimension"] = {"Meta Dimension","1 in 17,179,869,184", Color3.fromRGB(0, 4, 255), 34}
RollTypes["Meta Universe Dimension"] = {"Meta Universe Dimension","1 in 34,359,738,368", Color3.fromRGB(0, 255, 234), 35}
RollTypes["Dark Energy Dimension"] = {"Dark Energy Dimension","1 in 68,719,476,736", Color3.fromRGB(16, 0, 49), 36}
RollTypes["Dark Matter Dimension"] = {"Dark Matter Dimension","1 in 137,438,953,472", Color3.fromRGB(16, 0, 49), 37}
RollTypes["Dimension Ruler"] = {"Dimension Ruler","1 in 274,877,906,944", Color3.fromRGB(255, 0, 0), 38}

return RollTypes```
1 Like

I couldn’t really think of a way to add more dimensions without messing up the probability of rolling something…

but to reduce the number of lines, you can map the randomly generated number into an index corresponding to a value, which in this case is your dimension.

-- Store roll types in an indexable array instead of dictionary
local RollTypes = {

[1] = {"Common Dimension","1 in 2", Color3.fromRGB(255, 255, 255), 1},
[2] = {"Uncommon Dimension","1 in 4", Color3.fromRGB(125, 125, 125), 2},
[3] = {"Standard Dimension","1 in 8", Color3.fromRGB(255, 162, 162), 3},
[4] = {"Rare Dimension","1 in 16", Color3.fromRGB(93, 177, 255), 4},
[5] = {"Ultra Dimension","1 in 32", Color3.fromRGB(255, 198, 28), 5},
[6] = {"Superior Dimension","1 in 64", Color3.fromRGB(135, 113, 2), 6},
[7] = {"Absolute Dimension","1 in 128", Color3.fromRGB(21, 107, 57), 7},
[8] = {"Unleashed Dimension","1 in 256", Color3.fromRGB(91, 21, 108), 8},
[9] = {"Lightning Dimension","1 in 512", Color3.fromRGB(0, 255, 238), 9},
[10] = {"Matter Dimension","1 in 1,024", Color3.fromRGB(181, 43, 128), 10},
[11] = {"Starlight Dimension","1 in 2,048", Color3.fromRGB(255, 124, 58), 11},
[12] = {"Star Dimension","1 in 4,096", Color3.fromRGB(255, 239, 14)},
[13] = {"Nebula Dimension","1 in 8,192", Color3.fromRGB(136, 17, 255), 12},
[14] = {"Light Nebula Dimension","1 in 16,384", Color3.fromRGB(107, 63, 124), 13},
[15] = {"Dark Nebula Dimension","1 in 32,768", Color3.fromRGB(35, 32, 45), 14},
[16] = {"Absolute Nebula Dimension","1 in 65,536", Color3.fromRGB(165, 39, 255), 15},
[17] = {"Super Nova Dimension","1 in 131,072", Color3.fromRGB(52, 62, 255), 16},
[18] = {"Hyper Nova Dimension","1 in 262,144", Color3.fromRGB(43, 15, 255), 17},
[19] = {"Gamma Radiation Dimension","1 in 524,288", Color3.fromRGB(183, 0, 255), 18},
[20] = {"Gamma Ray Dimension","1 in 512,000", Color3.fromRGB(255, 0, 98), 19},
[21] = {"Black Hole Dimension","1 in 1,048,576", Color3.fromRGB(30, 30, 30), 20},
[22] = {"Light Galaxy Dimension","1 in 2,097,152", Color3.fromRGB(52, 228, 255), 21},
[23] = {"Dark Galaxy Dimension","1 in 4,194,304", Color3.fromRGB(29, 65, 58), 22},
[24] = {"Collection Dimension","1 in 8,388,608", Color3.fromRGB(255, 178, 247), 23},
[25] = {"Cluster Dimension","1 in 16,777,216", Color3.fromRGB(255, 170, 186), 24},
[26] = {"Fourth Dimension","1 in 33,554,432", Color3.fromRGB(249, 255, 130), 25},
[27] = {"Unidentified Dimension","1 in 67,108,864", Color3.fromRGB(35, 20, 21), 26},
[28] = {"Newfound Dimension","1 in 134,217,728", Color3.fromRGB(1, 69, 255), 27},
[29] =  {"Light Void Dimension","1 in 268,435,456", Color3.fromRGB(25, 25, 25), 28},
[30] = {"Dark Void Dimension","1 in 536,870,912", Color3.fromRGB(25, 25, 25), 29},
[31] = {"Void Dimension","1 in 1,073,741,824", Color3.fromRGB(17, 15, 13), 30},
[32] = {"Quantum Dimension","1 in 2,147,483,648", Color3.fromRGB(211, 255, 15), 31},
[33] = {"Infinity Dimension","1 in 4,294,967,296", Color3.fromRGB(255, 247, 0), 32},
[34] = {"Multiverse Dimension","1 in 8,589,934,592", Color3.fromRGB(0, 255, 42), 33},
[35] = {"Meta Dimension","1 in 17,179,869,184", Color3.fromRGB(0, 4, 255), 34},
[36] = {"Meta Universe Dimension","1 in 34,359,738,368", Color3.fromRGB(0, 255, 234), 35},
[37] = {"Dark Energy Dimension","1 in 68,719,476,736", Color3.fromRGB(16, 0, 49), 36},
[38] = {"Dark Matter Dimension","1 in 137,438,953,472", Color3.fromRGB(16, 0, 49), 37},
[39] = {"Dimension Ruler","1 in 274,877,906,944", Color3.fromRGB(255, 0, 0), 38}
	
}

local random = Random.new():NextInteger(0, 274877906944)

-- Converts the random number into the appropriate index
function numberToRollType(num)
	local newNum = math.log(num, 2) -- reduce the random number to a floating point between 0 to 38
	local compliment = 39 - newNum  -- get the compliment because the array is flipped 
	local index = math.floor(compliment) -- convert from float to an integer to make it indexable
	return index
end

local index = numberToRollType(random)
local rollInfo = RollTypes[index]
1 Like

(Sorry for late response)
Yeah, thanks!
I will mark this as a solution for now, until more posts come in!

1 Like

To answer your question on adding new dimensions, are you going to change the roll probabilities of the dimensions you have now? Or are they set in stone and the newer dimensions will all be rarer than “Dimension Ruler”?

No, I want to add dimensions in between. The current dimensions are based on powers of 2 all the way to 2^38.
I want to add rarities such as 1/200k and all that, but I don’t really know how to do that without changing all of the probabilities.

1 Like

Sorry for the late reply… had to do some calculations.

Given that there’s a finite number space, don’t want to change all the probabilities, and want to keep the powers of 2…

what you could do is “fake” the probability allowing you to add dimensions for whatever probability you want, although it’d be best to create dimensions for the more unlikely probabilities, i.e: 1 in 200,000; 1 in 500,000; and not 1 in 10.

  1. Create a separate table for new dimensions where the key is the ratio and the value is your rolltype.

eg) 1 in 200,000 → key = 200,000

nonLogRollTypes = {
[200,000] = {... roll type data...}
}
  1. Create a function that converts the random integer to a key that can be used for the table. This is similar to the numberToRollType() function here except we don’t round down (we want to retain the original random number’s identity)
    Need help with shortening and advancing RNG script - #2 by Vexeo
function numberToNonLogRollType(num)
 	local newNum = math.log(num, 2) -- reduce the random number to a floating point between 0 to 38
	local compliment = 39 - newNum  -- get the compliment (allows us to get the ratio)
        local ratio = 2 ^ compliment -- this is the ratio
end

This whole process is like converting your random integer, like 274877906944, into a ratio, like 1 in 2.

eg)

  1. log2(274877906944) = 38 (log the random number)
  2. 39 - 38 = 1 (compliment)
  1. 2^1 = 2 (the ratio)

The common dimension is 1 in 2.

Going back to our new table, we can now define keys as ratios like 1 in 200k, 1 in 5k, etc.

  1. Because we didn’t round the compliment and the new table isn’t indexed, we can’t use it as a key, however, we can test to see which of the non-log roll type ratios are the closest to our computed ratio.

Let’s define a function that gives us the roll type with the closest ratio:

function getClosestNonLogRollType(table, ratio)
       shortestDistance = nil
       bestRollType = nil
       
      for rollTypeRatio, rollType in pairs(nonLogRollTypes) do
            distance = math.abs(rollTypeRatio - ratio) 
            if (bestRollType == nil or distance < shortestDistance) then
                    shortestDistance = distance
                    bestRollType = rollType
           end
      end

     return bestRollType
end
  1. Now you have two roll types to choose from:
    I. One of your original roll types
    II. One of your newly added roll types

From here on, it’s up to you to decide how you want to choose between them.

You could randomly choose between the 2, or choose the one that has the ratio closest to the ratio rolled.

I haven’t compiled this and have only written the logic down on paper, but let me know if you have any questions or if anything’s not working.

2 Likes

wow this is a very good solution, I am going to try this out rn
I appreciate your hard work with this, and I’ll inform you if I encounter any problems!

Thanks!

So you are saying to make a new table like this for non log2()s:

[200,000] = {... roll type data...}

I’m kind of terrible at logs, but can we combine both the log2() and non-log2() tables?
We can technically do the index as the direct log like this:

math.round(math.log(200000,2)) = {... roll type data...} --Where 200000 is the ratio

And we can call the index like this:
local RollType = RollTypeTable[ratio] --Ratio is already logged with base of 2
I also got a bit confused with the 2 new introduced functions, can you make a total script showing the process between indexing both log2 and non-log2?

1 Like

Blockquote

The problem with this is that this index will clash with the original 39 indices you have.

In the example you gave me,

  1. math.log(200000,2) = 17.6
  2. math.round(17.6) = 18

Right now, the index for 18 from the original table is

[18] = {"Hyper Nova Dimension","1 in 262,144", Color3.fromRGB(43, 15, 255), 17},

What you probably want to do is add a new dimension anywhere you want which will shift all the other dimensions down.

[18] = {"Your New Dimension","1 in 200,000, Color3.fromRGB(43, 15, 255), 17},
[19] = {"Hyper Nova Dimension","1 in 262,144", Color3.fromRGB(43, 15, 255), 17},
...
...
...
[40] = {.......}

You cannot add any more dimensions to the original table given that you want to keep the probabilities related to the powers of 2. In the above example, the dimensions from 19-40 would have their probabilities messed up and halved; Hyper Nova Dimension wouldn’t be 1 in 262,144 but 1 in 512,000 and Dimension Ruler wouldn’t be 1 in 274,877,906,944 but 1 in 549,755,813,888. You can also see that we can’t generate a number from 274,877,906,944 to 549,755,813,888, so it’d be impossible to roll a dimension ruler type.

1 Like

So the current module script I have for the roll types have impossible rolls in them?

That’s only if you add new roll types to the current table. As long as you keep them separate, it’s still possible to roll the from current table.

Did you still need help with the 2 new functions?

I mean I rly don’t.
I just have one more question, I’m trying to make a 2x luck effect for a limited time (Stored in server side)
How do you think I can implement this?

I appreciate your help!