Attempt to index nil with 'Parent' Error

  1. What do you want to achieve?
    I want the console to stop being flooded with this error.

  2. What is the issue? The console keeps getting flooded and I don’t know how to fix it. image

The script:

local addConveyor = function(c)
	if c.Name == "CONVEYOR" then
		local con
		con = game:GetService("RunService").RenderStepped:Connect(function()
			if not (c.Parent or c.Parent.Parent) then con:Disconnect() end
			c.Parent.ConveyorTexture.OffsetStudsV = -(workspace.DistributedGameTime*c.Value)%(c.Parent.ConveyorTexture.StudsPerTileV)
		end)
	end
end

workspace.DescendantAdded:Connect(addConveyor)
for i,v in pairs(workspace:GetDescendants()) do
	addConveyor(v)
end
local addConveyor = function(c)
	if c.Name == "CONVEYOR" then
		local con
		con = game:GetService("RunService").RenderStepped:Connect(function()
			if not c or not c.Parent or not c.Parent.Parent then con:Disconnect() end
			c.Parent.ConveyorTexture.OffsetStudsV = -(workspace.DistributedGameTime*c.Value)%(c.Parent.ConveyorTexture.StudsPerTileV)
		end)
	end
end

workspace.DescendantAdded:Connect(addConveyor)
for i,v in pairs(workspace:GetDescendants()) do
	addConveyor(v)
end
2 Likes

The error arises with c.Parent. C is nil so when you try to get its parent you receive an error. Checking to see if c is not nil first should fix this error.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.