How do I use math.random() to get a random object value from a variable

I’m wanting to have a billboard GUI parent set to a random object in the game, but math.random() seems to only support int values instead of object values.

Code I have currently:

	    local randomParents = {game.Workspace, game.Teams, script.Parent, script.Parent.Parent, 
        game.ServerScriptService, game.Lighting}
		
		Username.Parent = math.random(randomParents)
		Username.Adronee = char:FindFirstChild("Head")
		
		TeamName.Parent = math.random((randomParents)
		TeamName.Adronee = char:FindFirstChild("Head")
1 Like

Hey,

local rand = math.random(1, #yourtable) 
local obj = yourtable[rand]
1 Like

You should do

local result = math.random(1, #randomParents)
username.Parent = randomParents[result]

caviar beat me to it lol

2 Likes