|
| 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 |
|
|
|
| 13 Aug 2015 12:56 PM |
| Probably a problem with your array |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
|
| 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 |
|
|
|
| 13 Aug 2015 12:58 PM |
Brick yellow???? Bright yellow
You may have messed the names up |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 13 Aug 2015 01:05 PM |
| ( And that what rayk said... How did I miss that? :/ ) |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 13 Aug 2015 01:25 PM |
| I've noticed when I use pcall my script still ceases from functioning :( |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|