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
 

Help with a simple script

Previous Thread :: Next Thread 
IAmTheRolo is not online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
10 Apr 2014 09:36 PM
Just began using tables, so I'm fairly new to them. Still can't get this to work though:

colors = {"Bright red", "Bright yellow", "Deep orange"}
while wait() do
colorchosen = math.random(1,#colors)
script.Parent.BrickColor = colorchosen
end

Output: 19:33:25.537 - Workspace.Center.Script:4: bad argument #3 to 'BrickColor' (BrickColor expected, got number)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 09:37 PM
colorchosen in your case is a number between 1-3, not the actual value in the table.

colorchosen = colors[math.random(1, #colors)] --index the value
and since BrickColor property takes a BrickColor value, not string, do:
script.Parent.BrickColor = BrickColor.new(colorchosen)
Report Abuse
IAmTheRolo is not online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
10 Apr 2014 09:39 PM
Thanks a lot mate! Cheers!
Report Abuse
Blockerjr800th is not online. Blockerjr800th
Joined: 24 May 2010
Total Posts: 3175
10 Apr 2014 09:40 PM
colors = {"Bright red", "Bright yellow", "Deep orange"}
while wait() do
colorchosen = math.random(1,#colors)
script.Parent.BrickColor = BrickColor.new(colors[colorchosen])
end

I think you can do that as also.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 09:42 PM
Yup, or event:

colors = {BrickColor.new("Bright red"), BrickColor.new("Bright yellow"), BrickColor.new("Deep orange")}

while wait() do
script.Parent.BrickColor = colors[math.random(#colors)]
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Apr 2014 09:42 PM
even*
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