So I’ve got this function here, and its stopped working ever since I added the color variable. The output says: “Unable to assign property Color. Color3 expected, got nil” Did I write it wrong or is there something more? (May I have caused a problem with adding a vector and not writing a value for it in the argument but instead in the variable?) Any is help is appreciated! Have a blessed day.
function run1(name,it,color,transparency)
local part = Instance.new("Part")
part.Name = name
part.Anchored = it
part.Color = color
part.Transparency = transparency
part.Position = Vector3.new(1,1,1)
print("Working")
print(part.Anchored)
part.Parent = game.Workspace
end
run1("New Part", true)
run1("Brand New Part")
run1("The Last Part",false,Color3.fromRGB(10,10,10),.1)
The first time you call the function run1("New Part", true), you did not parse the color argument. If you do not specify the color in the arguments it will be nil. The script then errors because you cannot set a part’s color to nil.
To fix this, simply specify the color when you call the function run1("New Part", true,Color3.fromRGB(10,10,10))
OR
rewrite the function so that it can “function” without the color argument.
function run1(name,it,color,transparency)
local part = Instance.new("Part")
part.Name = name
part.Anchored = it
part.Transparency = transparency
part.Position = Vector3.new(1,1,1)
if color then part.Color = color end
print("Working")
print(part.Anchored)
part.Parent = game.Workspace
end