Brick color expected, got function

Hi there,

I’m not sure why it won’t work, what is the alternative to make this piece of code work?

function createPart(color)
	local Part = Instance.new("Part") 
	Part.Size = Vector3.new(1,1,1)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Material = Enum.Material.SmoothPlastic
	Part.Parent = game.Workspace
	Part.BrickColor = color -- why won't it accept color
	return Part
end

In script*

local tweenService = game:GetService("TweenService")
local tweenInformation = TweenInfo.new(
	5,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)

function createPart(color)
	local Part = Instance.new("Part") 
	Part.Size = Vector3.new(1,1,1)
	Part.Anchored = true
	Part.CanCollide = false
	Part.Material = Enum.Material.SmoothPlastic
	Part.Parent = game.Workspace
	Part.BrickColor = color
	return Part
end

local partInfo1 ={
	Size = Vector3.new(2.5,0.3,2.5);
}

local partInfo2 = {
	Size = Vector3.new(2.7,0.2,2.7);
}

local function makeNewPartAndAnimate()
	local newPart1= createPart(BrickColor.Black)
	local newPart2= createPart(BrickColor.DarkGray)
	local tween1 = tweenService:Create(newPart1, tweenInformation, partInfo1)
	local tween2 = tweenService:Create(newPart1, tweenInformation, partInfo2)
	wait(10)
	tween1:Play()
	tween2:Play()
end

makeNewPartAndAnimate()

Make sure whenever you’re handling BrickColors to always do

BrickColor = BrickColor.new(BrickColor)

So to fix your issue change the line to:

Part.BrickColor = BrickColor.new(color)
2 Likes
Workspace.Script:17: invalid argument #1 to 'new' (Color3 expected, got function)

BrickColor.Black and BrickColor.DarkGray are technically functions as you use () on them aftterwards. Since you already seem t o be close, just change Part.BrickColor = color to Part.BrickColor = color()

3 Likes

Worked like a charm.
Appreciate it,
Naucify