Attempt to call a nil value on Instance:GetChildren()

I was trying to make a script to know which part is a model using the Instance:IsA() function and if it’s a model and the name is “Parts” then it finds a script that’s inside the model to enable it. The only problem is that it would throw me an error:

Workspace.TheWorldIsAboutToEnd.Part.MainScript:12: attempt to call a nil value
Here is the location of the objects:
Screenshot_2020_12_31_13_13_27

And here is the script:

local children = script.Parent.Parent.Parent:GetChildren()
for i,v in pairs(children) do
	if children:IsA("Model") and children.Name = "Parts" then
		children.CreatePart.Disabled = false
	end
end

Instead of children:IsAModel, children.CreatePart.Disabled and children.Name you have to do: v:IsAModel, v.CreatePart.Disabled = false and v.Name.

local children = script.Parent.Parent.Parent:GetChildren()
for i,v in pairs(children) do
	if v:IsA("Model") and v.Name = "Parts" then
		v.CreatePart.Disabled = false --Idk what this does.
	end
end

Fixed your code because you are trying to get the information of a table which is the GetChildren() instead of a children of it.

2 Likes

It worked, all I had to change is that instead of v.Name = “Parts”, I had to put 2 equal signs there.