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```