Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index local 'child,' what did I do wrong?

Hello fellow players, I've been modifying this old blackhole script which many of you might recognize and I've made it so it'll only unanchor parts that are within the range of the part (where the script is). When testing it has an error that says, "Workspace.DestroyP.TestCheck/BACKUPV2:27: attempt to index local 'child' (a nil value):." I don't really know what I did wrong but it keeps saying that, anyone know what I'm doing wrong?

local childList = {}
	function checkObject(obj)
	if (obj ~= script.Parent) and (obj.Name == "Breakable")  then
			table.insert(childList, 1, obj) 
elseif (obj.className == "Model") or (obj == workspace) then
		local child = obj:GetChildren()
		for x = 1, #child do
		checkObject(child[x])
		end
		obj.ChildAdded:connect(checkObject)
		end
end
checkObject(workspace)
local n = 0
	if n < #childList then
	n = n + 2
	if n % 800 == 0 then
			wait()
		end
	else
		n = 1
		wait()
	end

	local child = childList[n]
	if (child ~= script.Parent)  then
		local dis = (child.Position-script.Parent.Position).magnitude --right here is where the error occurs
		if dis <= 1 then
			child.Anchored = false
						wait()
					local n = n - 1
				end
			wait()
		end

1 answer

Is overriding table indexes, is what you want to do?

table.insert(childList, 1, obj)

1 comment

0

Yes that's needed for the script

This discussion is preserved as it was. New answers, comments, and votes are closed.