generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: random color issues

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:04 PM
tc[i].BrickColor = BrickColor.new(math.random(#Colors)) end end

I'm trying to call for the table "Colors" and it's pulling random colors not inside the table.

I also tried:
tc[i].BrickColor = BrickColor.new(Colors[math.random(#Colors)]) end end

While the second one did get only colors from the Colors table, they BOTH made all the part different colors instead of all one color.

I want them all to be one color, not a rainbow :/
Report Abuse
Noodess is not online. Noodess
Joined: 03 Jun 2012
Total Posts: 347
27 Dec 2013 12:07 PM
color = math.random(#Colors)

tc[i].BrickColor = BrickColor.new(color) end end

..?
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:12 PM
But that's exactly the same thing as the first try. The only difference is that you used a variable to call it, but it is the same thing.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:15 PM
If you have a table of colors and you want a random one use
rcolour = math.random(1, #Colors)

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:17 PM
RIGHT! I completely forgot that when calling for math.random, you have to specify the origin, in this case designating the origin as 1 random color in the table. Jeez I'm so stupid.
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:18 PM
But I'm still getting a rainbow out of it. :/
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:19 PM
Could you post the rest of the script?

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:21 PM
local tc = T.Chassis:GetChildren()
for i = 1, #tc do if tc[i].Name == "TC" then
tc[i].BrickColor = BrickColor.new(Colors[math.random(1, #Colors)]) end end
Report Abuse
Azureous is not online. Azureous
Joined: 29 Jan 2012
Total Posts: 25287
27 Dec 2013 12:21 PM
Example:

local colors = {'Bright blue', 'Really red', 'Violet'}

brick = Instance.new('Part', workspace)
brick.Color = BrickColor.new(colors[math.random(1,#colors)])
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
27 Dec 2013 12:22 PM
Did you define Colors?
Colors = {"Bright red", "Bright blue", "Magenta"} etc...
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:24 PM
Yes, I did. Not to sound rude, but look at my join date. I think I've been on roblox long enough to have earned some kind of trust in that I wouldn't forget such a trivial thing. :/
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:24 PM
local tc = T.Chassis:GetChildren()
leColor = math.random(1, #Colors)
for i = 1, #tc do if tc[i].Name == "TC" then
tc[i].BrickColor = BrickColor.new(Colors[leColor]) end end

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:25 PM
Mic that's the same thing I just posted. Making the math.random a variable won't change the fact it didn't work.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:26 PM
Reason:
Each time you went through the loop it generated a new random colour. You should of defined the colour before the loop so it wouldn't run math.random numerous times.

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:27 PM
Ok I'll try it then. It makes sense I guess o.o
Report Abuse
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
27 Dec 2013 12:28 PM
That fixed it. I'll try to remember that next time. Thank you very much.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:28 PM
No problem c:

Glad to help.

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
Noodess is not online. Noodess
Joined: 03 Jun 2012
Total Posts: 347
27 Dec 2013 12:29 PM
local tc = T.Chassis:GetChildren()
local Color = math.random(1, #Colors)
for i = 1, #tc do if tc[i].Name == "TC" then
tc[i].BrickColor = BrickColor.new(Colors[Color]) end end
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:30 PM
Late^
Tryina copy me just changing the variables? >:o

-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
CrniOrao is not online. CrniOrao
Joined: 12 Oct 2008
Total Posts: 2274
27 Dec 2013 12:32 PM
Not to worry, he tried to use your ladders.
Report Abuse
mic144 is not online. mic144
Joined: 14 Oct 2009
Total Posts: 1598
27 Dec 2013 12:33 PM
awwwhhh haiiil nawwwhhh

*knocks down ladders*


-- $$ Get on my level, here use this ladder. Don't fall down on the way up! $$ --
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image