My script wont print out a random part of the table

Im trying to make it so math.random prints a random part of GameRoulette

local GameRoulette = {"Murder Mystery", "Arsenal", "Roblox Uno", "Work At Pizza Place", "3008", "Paintball", "ZOぞ", "Outlaster", "Anime Tycoon", "Build A Boat", "Epic Minigames", "Escape The Dungon Obby", "Whacky Wizards", "Pakour", "Tower Of Hell", "Rage Runner", "Flee The Facility", "Boxing Leauge", "Breaking Point", "KAT", "Musical Chairs", "Broken Bones", "Natural Distars", "Obby Creator"}

print(math.random(GameRoulette))

Heres the error

  15:51:00.921  ServerScriptService.Script:3: invalid argument #1 to 'random' (number expected, got table)  -  Server - Script:3
  15:51:00.922  Stack Begin  -  Studio
  15:51:00.922  Script 'ServerScriptService.Script', Line 3  -  Studio - Script:3
  15:51:00.922  Stack End  -  Studio

I’ve seen this before. Here’s your solution.

print(GameRoulette[1, #GameRoulette])

2 Likes

When writing a script, putting a # before a table makes it represent the length of the table rather than the table itself.

  15:54:28.810  ServerScriptService.Script:3: Expected ']' (to close '[' at column 19), got ','  -  Studio - Script:3
print(GameRoulette[math.random(1, #GameRoulette)])

My bad, try this.

print(GameRoulette[math.random(1, #GameRoulette]))

2 Likes

Why did It print a number though?

Because it represents the length, and gives you a number. You’d have to use that random number by putting [randomNumber] after the name of the table, which returns the item in that position of a table/array.

Pass the length of the table instead of the table which return a random index, then you would want to get the string.

local GameRoulette = {"Murder Mystery", "Arsenal", "Roblox Uno", "Work At Pizza Place", "3008", "Paintball", "ZOぞ", "Outlaster", "Anime Tycoon", "Build A Boat", "Epic Minigames", "Escape The Dungon Obby", "Whacky Wizards", "Pakour", "Tower Of Hell", "Rage Runner", "Flee The Facility", "Boxing Leauge", "Breaking Point", "KAT", "Musical Chairs", "Broken Bones", "Natural Distars", "Obby Creator"}
print(GameRoulette[math.random(1, #GameRoulette)])