Well with your Error its being caused because the upper limit is lower than your lower limit
So
#gamemodes
Is less than or equal to 1
So math.random will always equal 1
this is because it is a dictionary, dictionaries are not able to be counted using “#table”
Try something like this
local Amount = 0
for I,_ in pairs(tablehere) do
Amount = Amount + 1
end
local choosenGM = math.random(1,Amount)
print(choosenGM)
what im trying to do is for Math.random to select from the table a gamemode and then i want to
print(ie:“FreeForAll”) not the number of GameModes in the Table.
Ah well when you print math.random() it will print a number
So you could use
local Amount = 0
for I,_ in pairs(tablehere) do
Amount = Amount + 1
end
local randomGM = math.random(1,Amount)
print(table[randomGM])
also if you try to print a dictionary i believe it will throw an error(or print the memory address i cant remember which)
so if you want to print the name i believe its…
yeah that doesnt work cause im not searching for a number error:
ServerScriptService.GameModeTable:25: invalid argument #2 to ‘random’ (interval is empty)
hmm i think i have a solution you could make keys for each gamemode in the Dictionary
so basically something like this
local randomNum = math.random(1,theamountofgamemodes) -- you have to put the amount in manually
if randomNum == 1 then
choosenGM = gamemodes.TDM
elseif randomNum == 2 then
choosenGM = gamemodes.FreeForAll
end
-- you also need to edit the amount of if statements for each new gamemode