How do I make a script that is easier and faster to type than this
Use a table:
local randomWords = {
"Word 1",
"Word 2",
"Word 3",
}
local chosenWord = randomWords[math.random(#randomWords)]
script.Parent.Text = chosenWord
2 Likes
local ItemTable = {
["1"] = "Apple";
["2"] = "Shirt";
["3"] = "Bone";
};
local RandomNumber = math.random(1,#ItemTable)
local RecievedObject = ItemTable[tostring(RandomNumber)]
script.Parent.Text = RecievedObject
This is another way to do but it’s more efficient to use the method mentioned above my post.
1 Like
Can I have a question? Why did you use stings as index? Isn’t is simpler to have them as numbers and avoid using tostring? Thank you
Correct me if i’m wrong but i’m not sure you can set values to integers.
1 Like
You can you have to either surround the numbers in brackets or completely omit them for an array. These two tables are the exact same
local firstTable = {
[1] = "First word",
[2] = "Second word"
}
local secondTable = {
"First word",
"Second word"
}
1 Like