Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why wont this table script work?

Asked by 8 years ago
 colors = {
"Lime green",
"Hot pink",
"Really black",
"White",
"Teal",

}
while true do
script.Parent.BrickColor = BrickColor.new(math.random(1, #colors))
wait(1)

end

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

You're asking the script to choose a random number between 1 and 5, but you're not using that number to do anything.

Let's say for example the random number it got was 3. If we put this into the script the way you have it set up, it would be like doing this:

script.Parent.BrickColor = BrickColor.new(3)

This is clearly incorrect, because 3 isn't the brickcolor.


To fix your script, we simply need to use the number we get to extract the corresponding string from the table. We'll do that like so:

script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)])

Now this would work correctly, and get the correct string from the table rather than a number. Your finished script should look like this:

 colors = {
"Lime green",
"Hot pink",
"Really black",
"White",
"Teal",
}

while true do
    script.Parent.BrickColor = BrickColor.new(colors[math.random(1, #colors)])
    wait(1)
end

There you go! Anyways, I hope I helped. If you have any further problems/questions, please leave a comment below :P

-Dyler3

Ad

Answer this question