Attempt to index nil with 'Size' and attempt to index nil with 'Color'

local TestPartsFolder = workspace.TestParts

local ToggleButton = script.Parent

local ClickSound = script.Click

local Toggled = false

local TestPartStorage = game:GetService("ReplicatedStorage"):WaitForChild("TestPartStorage")

local ButtonColors = {
	NotInUsed = {
		Main = Color3.fromRGB(85, 255, 127);
		Shadow = Color3.fromRGB(77, 232, 113);
	InUse = {
		Main = Color3.fromRGB(240, 0, 0);
		Shadow = Color3.fromRGB(220, 0, 0);

local InfoBoards = workspace.TestPartArea.InfoBoards:GetChildren()

local function SetInfoBoard(Quantity, Color, Shape, Size, PartsPerSec)
	local formattedQuantity = string.format("%d", Quantity):reverse():gsub("%d%d%d", "%0,"):reverse():gsub("^,", "")
	for _, InfoBoard in pairs(InfoBoards) do
		InfoBoard.SurfaceGui.Background.PartQuantity.Text = "Quantity: " .. formattedQuantity
		InfoBoard.SurfaceGui.Background.PartColor.Text = "Color: " .. tostring(Color)
		InfoBoard.SurfaceGui.Background.PartShape.Text = "Shape: " .. Shape
		InfoBoard.SurfaceGui.Background.PartSize.Text = "Size: " .. Size
		InfoBoard.SurfaceGui.Background["Parts/Sec"].Text = PartsPerSec .. " parts/s"

local plr = game.Players.LocalPlayer

	if Toggled == false then
		Toggled = true
		ToggleButton.Text = "Stop"
		ToggleButton.BackgroundColor3 = ButtonColors.InUse.Main
		ToggleButton.Shadow.BackgroundColor3 = ButtonColors.InUse.Shadow
		local StartTime = os.time()
		-- Test Part Config
		local PartColor = plr.TestPartConfig.Color.Value
		local PartShape = plr.TestPartConfig.Shape.Value
		local PartSize = plr.TestPartConfig.Size.Value
		local PartsCreated = 0
		while true do
			if Toggled == true then
				local ClonedPart = TestPartStorage:FindFirstChild(PartShape)

				ClonedPart.Color = PartColor

				ClonedPart.Size =,PartSize,PartSize)

				ClonedPart.CFrame =,388.5,0)

				ClonedPart.Parent = TestPartsFolder
				PartsCreated = PartsCreated + 1

				if os.time() - StartTime >= 1 then
					SetInfoBoard(tostring(#TestPartsFolder:GetChildren()),,PartShape,tostring(PartSize), tostring(PartsCreated))
					PartsCreated = 0
					StartTime = os.time()
				SetInfoBoard(tostring(#TestPartsFolder:GetChildren()),,PartShape,tostring(PartSize), tostring(PartsCreated))

		Toggled = false
		ToggleButton.Text = "Start"
		ToggleButton.BackgroundColor3 = ButtonColors.NotInUsed.Main

		ToggleButton.Shadow.BackgroundColor3 = ButtonColors.NotInUsed.Shadow

I’ve checked the folder where the values are stored and they arent nil

Line 78 and 80

1 Like

These lines?

ClonedPart is nil. Does PartShape hold the name of an actual Instance in TestPartStorage?

I checked the values and they ain’t nil

You added a print() statement right after this line? And the two lines of code after this are the ones throwing the errors, right?

I don’t know why, but the value you are trying to get whatever property or Instance from is nil. The “Attempt to index nil” error occurs when you are trying to index something from a nil value.

Also, don’t forget to call the Instance:Clone() method if needed.

Because of this error I’ modified the code a little and did this instead

local AvailableColors = {RGB values here}

local ChosenColor = AvailableColors[math.random(1,#AvailableColors]


But it doesn’t seem to return a color

(I actually have Color3 values in the tables but in the actual code this is just a example)

I believe your problem may be occurring due to one or two things:

  1. ClonedPart is a variable that is referencing a child that is equal to a value inside of TestPartStorage and values dont have Color or Size properties

  2. ClonedPart is being parented to TestPartsFolder where it then cannot be referenced again because it seems as if ClonedPart is not actually a clone and just a direct reference

One big thing to make sure of is that the value you are referencing is actually set to something and not just an empty value or else it will return nil no matter the circumstance

The color value is a Color3Value instance

Should I just redo the entire script and put prints after every if statements? Also should I always print bc I don’t usually print anything unless errors