-
What do you want to achieve? Keep it simple and clear!
Currently i’m making an game where with random you get some gens,
but when i’m using randomizing chances i get an error here is it -
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I was looking an vid on youtube and it should work
Code:
local ST = game:GetService("ServerStorage")
local ChancesModule = require(ST.ChanceModule)
local Players = game.Players
local function GetRandomGen()
local Sum = 0
for GenName,Chance in pairs(ChancesModule) do
Sum += Chance
end
local RandomNumber = math.random(Sum)
for GenName, Chance in pairs(ChancesModule) do
if RandomNumber <= Chance then
return GenName
else
RandomNumber -= Chance
end
end
end
Players.PlayerAdded:Connect(function(plr)
print("Plr Added")
plr.CharacterAdded:Connect(function(Char)
print("Char Added")
local pHead = Char:FindFirstChild("Head")
if pHead:FindFirstChild("AdvancedGameGUI") then
print("Advanced GUI Found")
print(GetRandomGen())
else
if pHead:WaitForChild("AdvancedGameGUI") then
print(GetRandomGen())
end
end
end)
end)
Here is Chances:
return {
["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
}