How to make a lots of values(50) to one datastore and how to make very small chances(ex. 1/1qn)

  1. What do you want to achieve? Keep it simple and clear!
    So basically i’m currently making an game where you have 50 generators, each of them you could get randomly each 2s(could be lower with upgrades), each generator have it own chance, like this:
    Generator | Chance
    Gen1 | 1/1
    Gen2 | 1/125
    Gen3 | 1/1000
    Gen4 | 1/12500
    and etc.
    I need to make really small chances for each gen(around more than e54), but in case of roblox limitations i can’t set those numbers normally, i already have table with all chances, here it is
local ChancesTable = {
	Gen1 = 1,
	Gen2 = 125,
	Gen3 = 1250,
	Gen4 = 12500,
	Gen5 = 125000,
	Gen6 = 1250000,
	Gen7 = 12500000,
	Gen8 = 125000000,
	Gen9 = 1250000000,
	Gen10 = 12500000000,
	Gen11 = 250000000000,
	Gen12 = 5000000000000,
	Gen13 = 100000000000000,
	Gen14 = 2000000000000000,
	Gen15 = 40000000000000000,
	Gen16 = 800000000000000000,
	Gen17 = 16000000000000000000,
	Gen18 = 320000000000000000000,
	Gen19 = 6400000000000000000000,
	Gen20 = 128000000000000000000000,
	Gen21 = 12800000000000000000000000,
	Gen22 = 1280000000000000000000000000,
	Gen23 = 128000000000000000000000000000,
	Gen24 = 1280000000000000000000000000000,
	Gen25 = 128000000000000000000000000000000,
	Gen26 = 12800000000000000000000000000000000,
	Gen27 = 1280000000000000000000000000000000000,
	Gen28 = 128000000000000000000000000000000000000,
	Gen29 = 12800000000000000000000000000000000000000,
	Gen30 = 1280000000000000000000000000000000000000000,
	Gen31 = 128000000000000000000000000000000000000000000,
	Gen32 = 12800000000000000000000000000000000000000000000,
	Gen33 = 1280000000000000000000000000000000000000000000000,
	Gen34 = 128000000000000000000000000000000000000000000000000,
	Gen35 = 12800000000000000000000000000000000000000000000000000,
	Gen36 = 1280000000000000000000000000000000000000000000000000000,
	Gen37 = 128000000000000000000000000000000000000000000000000000000,
	Gen38 = 12800000000000000000000000000000000000000000000000000000000,
	Gen39 = 1280000000000000000000000000000000000000000000000000000000000,
	Gen40 = 128000000000000000000000000000000000000000000000000000000000000,
	Gen41 = 256000000000000000000000000000000000000000000000000000000000000000,
	Gen42 = 512000000000000000000000000000000000000000000000000000000000000000000,
	Gen43 = 1024000000000000000000000000000000000000000000000000000000000000000000000,
	Gen44 = 2048000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen45 = 4096000000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen46 = 8192000000000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen47 = 16384000000000000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen48 = 32768000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen49 = 65536000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
	Gen50 = 131072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
}

And second problem i need to store amount of each generator without using 50 datastore values(due optimization), how i can store them all in one value?
2. What is the issue? Include screenshots / videos if possible!
Idk how to make it
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tryed to use converter script instead, but idk how to connect it with Chances

Here is my code of datastore:

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")
local protectedCall = pcall

local function onPlayerJoined(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = player

	local PlayerGUIType = Instance.new("StringValue")
	PlayerGUIType.Name = "GUIType"
	PlayerGUIType.Parent = StatsFolder
	
	local PlayerGraphicsType = Instance.new("StringValue")
	PlayerGraphicsType.Name = "GraphicsType"
	PlayerGraphicsType.Parent = StatsFolder
	
	local FirstVisitValue = Instance.new("BoolValue")
	FirstVisitValue.Name = "GameVisited"
	FirstVisitValue.Parent = StatsFolder
	
	local PowerVal = Instance.new("NumberValue")
	PowerVal.Name = "Power"
	PowerVal.Parent = leaderstats
	
	local RebirthsAmountVal = Instance.new("NumberValue")
	RebirthsAmountVal.Name = "RebirthsAmount"
	RebirthsAmountVal.Parent = StatsFolder
	
	local RebirthPointsVal = Instance.new("RebirthPointsVal")
	RebirthPointsVal.Name = "RP"
	RebirthPointsVal.Parent = StatsFolder
	
	local PlayerLuck = Instance.new("NumberValue")
	PlayerLuck.Name = "PlrLuck"
	PlayerLuck.Parent = StatsFolder
	
	local PlayerMoney = Instance.new("NumberValue")
	PlayerMoney.Name = "PlrMoney"
	PlayerMoney.Parent = StatsFolder
	
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				PlayerGUIType.Value = result[1] or "Standart"
				PlayerGraphicsType.Value = result[2] or "Low"
				FirstVisitValue.Value = result[3] or false
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.Stats.GUIType.Value, player.Stats.GraphicsType.Value, player.Stats.GameVisited.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.Stats.GUIType.Value, player.Stats.GraphicsType.Value, player.Stats.GameVisited.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

And here is code of set chances system:

local Players = game:GetService("Players")
	local ChancesTable = {
		Gen1 = 1,
		Gen2 = 125,
		Gen3 = 1250,
		Gen4 = 12500,
		Gen5 = 125000,
		Gen6 = 1250000,
		Gen7 = 12500000,
		Gen8 = 125000000,
		Gen9 = 1250000000,
		Gen10 = 12500000000,
		Gen11 = 250000000000,
		Gen12 = 5000000000000,
		Gen13 = 100000000000000,
		Gen14 = 2000000000000000,
		Gen15 = 40000000000000000,
		Gen16 = 800000000000000000,
		Gen17 = 16000000000000000000,
		Gen18 = 320000000000000000000,
		Gen19 = 6400000000000000000000,
		Gen20 = 128000000000000000000000,
		Gen21 = 12800000000000000000000000,
		Gen22 = 1280000000000000000000000000,
		Gen23 = 128000000000000000000000000000,
		Gen24 = 1280000000000000000000000000000,
		Gen25 = 128000000000000000000000000000000,
		Gen26 = 12800000000000000000000000000000000,
		Gen27 = 1280000000000000000000000000000000000,
		Gen28 = 128000000000000000000000000000000000000,
		Gen29 = 12800000000000000000000000000000000000000,
		Gen30 = 1280000000000000000000000000000000000000000,
		Gen31 = 128000000000000000000000000000000000000000000,
		Gen32 = 12800000000000000000000000000000000000000000000,
		Gen33 = 1280000000000000000000000000000000000000000000000,
		Gen34 = 128000000000000000000000000000000000000000000000000,
		Gen35 = 12800000000000000000000000000000000000000000000000000,
		Gen36 = 1280000000000000000000000000000000000000000000000000000,
		Gen37 = 128000000000000000000000000000000000000000000000000000000,
		Gen38 = 12800000000000000000000000000000000000000000000000000000000,
		Gen39 = 1280000000000000000000000000000000000000000000000000000000000,
		Gen40 = 128000000000000000000000000000000000000000000000000000000000000,
		Gen41 = 256000000000000000000000000000000000000000000000000000000000000000,
		Gen42 = 512000000000000000000000000000000000000000000000000000000000000000000,
		Gen43 = 1024000000000000000000000000000000000000000000000000000000000000000000000,
		Gen44 = 2048000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen45 = 4096000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen46 = 8192000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen47 = 16384000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen48 = 32768000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen49 = 65536000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen50 = 131072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	}
Players.PlayerAdded:Connect(function(plr)
	local StatsFolder = plr:WaitForChild("Stats")
	local FirstJoinValue = StatsFolder:WaitForChild("GameVisited")
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local SettingsGUI = ReplicatedStorage:WaitForChild("SettingsFrame")
	local AdvancedGameGUI = ReplicatedStorage:WaitForChild("AdvancedGameGUI")
	local GUISettings = StatsFolder:WaitForChild("GUIType")
	wait(1)
	if FirstJoinValue.Value == false then
		SettingsGUI.Parent = plr.PlayerGui
	end
	if GUISettings.Value == "Advanced" then
		local AGGUIClone = AdvancedGameGUI:Clone()
		local pName = plr.Name
		local pCharacter = workspace:FindFirstChild(pName)
		local pHead = pCharacter:WaitForChild("Head")
		AGGUIClone.Parent = pHead
		local Frame = AGGUIClone:FindFirstChild("Frame")
		for i,lines in ipairs(Frame:GetChildren()) do --- Here is exact code how i set Chances when player join(To not use datastores for them)
			for i, values in ipairs(lines:GetDescendants()) do
				for i, gens in pairs(ChancesTable) do
					values.Value = gens
				end
			end
		end
	end
end)

After running this code i’m getting this error:
image

To save them all to a datastore you can put all player data including the gens into a table and then save that with the player’s userid as the key.

You mean i can put all values, chance, CurrentChance and amount into one table? Also still i can’t set numbers from chance table to chanceValue by me in case of roblox limitations, so i need to set it with script i think

alright when i’m trying to save value i see this

I get an roblox syntax error, but i need to get all values i wanna get exact value and then sent it as Gen1Amount = value for ex.

Values that big will just become inf aka math.huge. You could use modulescripts instead of values if you really need them represented physically.

Ohhh, i know what game called Luck Simulator Better use module script for that
Here is screenshot from this game what i wanna do(this is just chances):
image
But i don’t even have idea how to make this module script

I’m not familiar with luck simulator, but what I’m getting from this is you want people to have a chance of getting something that starts really small but becomes closer to 100% chance with every upgrade?

Yes that’s exact what i wanna do, i have an special value for that “PlayerLuck” I will just make GenChance / PlayerLuck and decrease chances, but exact is what this game use these huge values(this is >1e250)

So if the gen chance is the same for everybody, all you have to do is store all the chances somewhere (probably a modulescript in server storage) and then just save the player’s luck along with any other data in a table.

Hmm, module script, lemme try do smth like that, should i use smth like i stated at top

local ChancesTable = {
		Gen1 = 1,
		Gen2 = 125,
		Gen3 = 1250,
		Gen4 = 12500,
		Gen5 = 125000,
		Gen6 = 1250000,
		Gen7 = 12500000,
		Gen8 = 125000000,
		Gen9 = 1250000000,
		Gen10 = 12500000000,
		Gen11 = 250000000000,
		Gen12 = 5000000000000,
		Gen13 = 100000000000000,
		Gen14 = 2000000000000000,
		Gen15 = 40000000000000000,
		Gen16 = 800000000000000000,
		Gen17 = 16000000000000000000,
		Gen18 = 320000000000000000000,
		Gen19 = 6400000000000000000000,
		Gen20 = 128000000000000000000000,
		Gen21 = 12800000000000000000000000,
		Gen22 = 1280000000000000000000000000,
		Gen23 = 128000000000000000000000000000,
		Gen24 = 1280000000000000000000000000000,
		Gen25 = 128000000000000000000000000000000,
		Gen26 = 12800000000000000000000000000000000,
		Gen27 = 1280000000000000000000000000000000000,
		Gen28 = 128000000000000000000000000000000000000,
		Gen29 = 12800000000000000000000000000000000000000,
		Gen30 = 1280000000000000000000000000000000000000000,
		Gen31 = 128000000000000000000000000000000000000000000,
		Gen32 = 12800000000000000000000000000000000000000000000,
		Gen33 = 1280000000000000000000000000000000000000000000000,
		Gen34 = 128000000000000000000000000000000000000000000000000,
		Gen35 = 12800000000000000000000000000000000000000000000000000,
		Gen36 = 1280000000000000000000000000000000000000000000000000000,
		Gen37 = 128000000000000000000000000000000000000000000000000000000,
		Gen38 = 12800000000000000000000000000000000000000000000000000000000,
		Gen39 = 1280000000000000000000000000000000000000000000000000000000000,
		Gen40 = 128000000000000000000000000000000000000000000000000000000000000,
		Gen41 = 256000000000000000000000000000000000000000000000000000000000000000,
		Gen42 = 512000000000000000000000000000000000000000000000000000000000000000000,
		Gen43 = 1024000000000000000000000000000000000000000000000000000000000000000000000,
		Gen44 = 2048000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen45 = 4096000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen46 = 8192000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen47 = 16384000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen48 = 32768000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen49 = 65536000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen50 = 131072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	}

But in same moment i need to get those values from module script

Alright so i made smth like that to get chances

local ChanceModule = {}
function ChanceModule.chances(chance)
	local ChanceTable = {
		Gen1 = 1,
		Gen2 = 1/125,
		Gen3 = 1/1250
	}
	for i, chance in pairs(ChanceTable) do
		return chance
	end	
end
function ChanceModule.storechances(chance)
	local Gen1 = 1/chance
	local Gen2 = 1/chance
	local Gen3 = 1/chance
end
return ChanceModule

so if all generators have the same chance and the only thing that differs from player to player is their luck value (which effects all generators) then you can easily put all the values in a modulescript like this:

local ChancesTable = {
		Gen1 = 1,
		Gen2 = 125,
		Gen3 = 1250,
		Gen4 = 12500,
		Gen5 = 125000,
		Gen6 = 1250000,
		Gen7 = 12500000,
		Gen8 = 125000000,
		Gen9 = 1250000000,
		Gen10 = 12500000000,
		Gen11 = 250000000000,
		Gen12 = 5000000000000,
		Gen13 = 100000000000000,
		Gen14 = 2000000000000000,
		Gen15 = 40000000000000000,
		Gen16 = 800000000000000000,
		Gen17 = 16000000000000000000,
		Gen18 = 320000000000000000000,
		Gen19 = 6400000000000000000000,
		Gen20 = 128000000000000000000000,
		Gen21 = 12800000000000000000000000,
		Gen22 = 1280000000000000000000000000,
		Gen23 = 128000000000000000000000000000,
		Gen24 = 1280000000000000000000000000000,
		Gen25 = 128000000000000000000000000000000,
		Gen26 = 12800000000000000000000000000000000,
		Gen27 = 1280000000000000000000000000000000000,
		Gen28 = 128000000000000000000000000000000000000,
		Gen29 = 12800000000000000000000000000000000000000,
		Gen30 = 1280000000000000000000000000000000000000000,
		Gen31 = 128000000000000000000000000000000000000000000,
		Gen32 = 12800000000000000000000000000000000000000000000,
		Gen33 = 1280000000000000000000000000000000000000000000000,
		Gen34 = 128000000000000000000000000000000000000000000000000,
		Gen35 = 12800000000000000000000000000000000000000000000000000,
		Gen36 = 1280000000000000000000000000000000000000000000000000000,
		Gen37 = 128000000000000000000000000000000000000000000000000000000,
		Gen38 = 12800000000000000000000000000000000000000000000000000000000,
		Gen39 = 1280000000000000000000000000000000000000000000000000000000000,
		Gen40 = 128000000000000000000000000000000000000000000000000000000000000,
		Gen41 = 256000000000000000000000000000000000000000000000000000000000000000,
		Gen42 = 512000000000000000000000000000000000000000000000000000000000000000000,
		Gen43 = 1024000000000000000000000000000000000000000000000000000000000000000000000,
		Gen44 = 2048000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen45 = 4096000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen46 = 8192000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen47 = 16384000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen48 = 32768000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen49 = 65536000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
		Gen50 = 131072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
	}
return ChancesTable

and then the server script getting the module:

local chanceModule = require(game.ServerStorage.ChanceModule)

server script looping through the values:

for i,v in pairs(chanceModule) do
	print(i,v)
end

Alright that’s print all values, but there is still an problem which is that script prints all values randomly, not by order like i get 1.25m and after that 1.25qd instead of 12.5m

if you want to loop through them in order use ipairs instead of pairs and an array instead if a dictionary.

You mean?

 for i,v in ipairs(chanceModule["Chance"]) do
print(i,v)
end

Alright anyways, so i’m currently starting to make an GenRandomScript(which gives you gen), i now got some issues with how to make random chance to get it each two seconds, here is script

local SSS = game:GetService("ServerScriptService")
local ChanceModule = require(SSS.ChanceModule)
local Players = game.Players
Players.PlayerAdded:Connect(function(plr)
	local PlrGUI = plr.PlayerGui
	local PowerVal = plr.leaderstats.Power
	local PlayerLuck = plr.Stats.PlrLuck
	if PlrGUI:FindFirstChild("AdvancedGameGUI") then
		for i,v in ipairs(ChanceModule) do
--[[
So exacty here i need to randomize which gens player
get using random.math i think, but then i need to save 50 values, 
but i think there is an better method
--]]
		end
	else
		return
	end
end)

I’m confused. Are you saying that when the player joins you want them to get a couple random gens? I don’t even know what a gen is. Please elaborate.

kk Player have an GUI:
image
Each of these Generator have own chance, own production and own amount,
I currently adding an array in table for Production
So each 2 seconds every generator depends on it amount gives power(or money if this is easier to understand)
Amount | GenNumber | Production | Exact Production
1 | 1 | 1 | AmountProduction(11 = 1)
5 | 2 | 25 | AmountProduction(525 = 125)
And etc
And each 2 seconds there an chance what you get new generator like
Chance | GenTier | Amount
50 | 1 | 1 or 0
100 | 1 | 1

And also if chance is already 100 you just get more luck like:
First upgrade after chance 100 gives 1 gen
Second upgrade after chance 100 gives 2gen
and etc.

Alright just done an Array for Production

Alright here is smth what i made:

local SSS = game:GetService("ServerScriptService")
local GameInstancesModule = require(SSS.GameInstancesModule)
local Players = game.Players
Players.PlayerAdded:Connect(function(plr)
	local PlrGUI = plr.PlayerGui
	local PowerVal = plr.leaderstats.Power
	local PlayerLuck = plr.Stats.PlrLuck
	if PlrGUI:FindFirstChild("AdvancedGameGUI") then
		for i,v in ipairs(GameInstancesModule.Chances) do
				local TrueChance = v/PlayerLuck
				local randomNumber = math.random(1,v)
				if randomNumber == 1 then
					-- here need to change amount in table array
				end
				wait(0.01)
		end
	else
		return
	end
end)