Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Randomly choosing a value from a table and printing it? [Answered]

I'm trying to get my script to choose a random value from a table and then print it, but instead of text, it comes out with something like table: 1F19D310

local messages = {
	"One little piggy went to market",
	"One little doggy went to market",
	"One little child went to market",
	"One little man went to market"
}
local random = messages[math.random(#messages)]
print(random)

3 comments

0

This works?

0

What do you mean? This code works the way you've intended it to. It prints out a random from the array.

0

I've intended it to print the text, not a random sequence.

2 answers

You can't local a local. Try this:

print('Test') else print('Test2') else print('Test3') else print('Test4')

I'm not that good at random variables, sorry.

Please don't down my REP ^

1 comment

0

How's this going to solve my problem? Not trying to be rude, but I don't really see how it will help.

Answered

local messages = {
	"One little piggy went to market",
	"One little doggy went to market",
	"One little child went to market",
	"One little man went to market"
}
local random = math.random(1,#messages) --Forgot to choose from the table, so it would choose #messages instead of in between them
print(messages[random]) --Prints it :3

This discussion is preserved as it was. New answers, comments, and votes are closed.