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 » Scripters
Home Search
 

Re: Hey... Does roblox despise brickcolor names or somthing?

Previous Thread :: Next Thread 
randomsmileyface is online. randomsmileyface
Joined: 01 Aug 2010
Total Posts: 4538
13 Aug 2015 12:55 PM
I was running this as Part of a Loop:

v.BrickColor = BrickColor.new(Colors[counter])
--Colors[counter] indexes a string name for a BrickColor in an array

Many times it would work very smoothly, but every once in a while, given the same exact conditions as before, it would produce this error

bad argument #1 to 'new' (Color3 expected, got BrickColor)

Would someone please explain this?
Report Abuse
zarman3402 is not online. zarman3402
Joined: 18 May 2013
Total Posts: 1449
13 Aug 2015 12:56 PM
Probably a problem with your array
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Aug 2015 12:57 PM
Post code.
Report Abuse
randomsmileyface is online. randomsmileyface
Joined: 01 Aug 2010
Total Posts: 4538
13 Aug 2015 12:57 PM
But its the exact same every time...

Bright yellow
Bright red
Brick yellow
Brick yellow
Medium stone grey
Medium stone grey
Report Abuse
zarman3402 is not online. zarman3402
Joined: 18 May 2013
Total Posts: 1449
13 Aug 2015 12:58 PM
Brick yellow????
Bright yellow

You may have messed the names up
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
13 Aug 2015 12:59 PM
we'd have to see more of your script at this rate i think, but i'd recommend using pcall
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
13 Aug 2015 01:02 PM
v.BrickColor = Colors[counter]

You can't create a BrickColor out of a BrickColor, silly
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
13 Aug 2015 01:03 PM
Why should he use pcall?... I don't see the reason...

anyway. instead of using names how about using their ID's?

http://wiki.roblox.com/index.php?title=BrickColor_Codes

Report Abuse
randomsmileyface is online. randomsmileyface
Joined: 01 Aug 2010
Total Posts: 4538
13 Aug 2015 01:04 PM
Well I'm not going to post All of my code, but here's the functions which are relevant.

local Colors = {}
local counter = 1
for v in string.gmatch(Tool.Colors.Value, "([%a%s]+),") do
Colors[counter]= v
print(Colors[counter])
counter = counter +1
end

local function CountColor(Parts) --Tracks all the Colors in the model and its descendants using array Colors. Also stores it in StringValue Colors to call upon when script is ran a second time.
for _, v in ipairs(Parts:GetChildren()) do
if v:IsA("BasePart") then
Tool.Colors.Value = Tool.Colors.Value..tostring(v.BrickColor)..","
Colors[counter] = v.BrickColor
counter = counter + 1

elseif v:IsA("Model") then
CountColor(v)
end
end
end

local function RestoreColor(Parts) -- restores Colors of model and descendants using array Colors
for _, v in ipairs(Parts:GetChildren()) do
if v:IsA("BasePart") then
v.BrickColor = BrickColor.new(Colors[counter])
print(counter, v.BrickColor)
counter = counter + 1

elseif v:IsA("Model") then
RestoreColor(v)
end
end
end

function drawLaser(Start, Finish, Reverse, Model)
local magnitude = (Start - Finish).magnitude
local laser = Instance.new("Part", Tool)
if Reverse == false then
laser.BrickColor = BrickColor.new("Bright red")
else
laser.BrickColor = BrickColor.new("White")
end
laser.Transparency = .4
laser.Anchored = true
laser.CanCollide = false
laser.TopSurface = Enum.SurfaceType.Smooth
laser.BottomSurface = Enum.SurfaceType.Smooth
laser.formFactor = Enum.FormFactor.Custom
laser.Size = Vector3.new(0.2, 0.2, magnitude)
laser.CFrame = CFrame.new(Start, Finish) * CFrame.new(0, 0, -magnitude/2)
wait(.05)

if Reverse == false then
print("Capture")
CountColor(Model)
for i = .4, 1, .1 do
EditAllParts(Model, i, "Bright red")
laser.Transparency = i
wait(.05)
end
else
print("Release")
for i = 0.6, 0, -.1 do
EditAllParts(Model, i, "White")
laser.Transparency = i
wait(.05)
end
counter = 1
RestoreColor(Model)
Colors = {}
counter = 1
end

laser:Destroy()
end
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
13 Aug 2015 01:05 PM
( And that what rayk said... How did I miss that? :/ )
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
13 Aug 2015 01:07 PM
"Why should he use pcall?... I don't see the reason...

anyway. instead of using names how about using their ID's?"

so that error wouldn't completely cease his script from functioning

and i'll read your script in a moment, OP
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
13 Aug 2015 01:08 PM
o ya ray is right m8
Report Abuse
randomsmileyface is online. randomsmileyface
Joined: 01 Aug 2010
Total Posts: 4538
13 Aug 2015 01:10 PM
erm...
How is ray right?
all of these objects in the array are STRINGS.
BrickColor.new() Creates a new BrickColor from a string.

or else you get error message
bad argument #3 to 'BrickColor' (BrickColor expected, got string)

http://wiki.roblox.com/index.php?title=BrickColor
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
13 Aug 2015 01:12 PM
Yeah I noticed my error before you guys started praising me lolllllll
Report Abuse
randomsmileyface is online. randomsmileyface
Joined: 01 Aug 2010
Total Posts: 4538
13 Aug 2015 01:25 PM
I've noticed when I use pcall my script still ceases from functioning :(
Report Abuse
buildersteven4 is not online. buildersteven4
Joined: 08 May 2009
Total Posts: 1325
13 Aug 2015 01:31 PM
I'd rather have my scripts crash hard than silently malfunction. Silent malfunctions can lead to very hard to track bugs. I only use pcall when I run code dynamic 3rd party code.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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