Table not fully getting printed

Hi devs,

I have been working on this for a while now but keep running into this isue. The script takes all children in the folder and then should fill the table in for every part, this works for most of the variables but the last 3 never fill in. I have tried multible things but it just doesn’t do what it is supost to do. I also don’t get errors so I have no idea what could be wrong.

Code:

local DataString = {
		["PartName"] = {
			Material = nil,
			Parent = nil,
			ColorR = nil,
			ColorG = nil,
			ColorB = nil,
			PosX = nil,
			PosY = nil,
			PosZ = nil,
			SizeX = nil,
			SizeY = nil,
			SizeZ = nil,
			Anchored = false,
			ClassName = nil,
			HasChildren = false
		}
	}
	
	for _, P in pairs(Children) do
		local Part = P
		DataString.Part.Material = Part.Material
		DataString.Part.Parent = Part.Parent.Name
		DataString.Part.ColorR = Part.Color.R
		DataString.Part.ColorG = Part.Color.G
		DataString.Part.ColorB = Part.Color.B
		DataString.Part.PosX = Part.Position.X
		DataString.Part.PosY = Part.Position.Y
		DataString.Part.PosZ = Part.Position.Z
		DataString.Part.SizeX = Part.Size.X
		DataString.Part.SizeY = Part.Size.Y
		DataString.Part.SizeZ = Part.Size.Z
	
		if Part.Anchored == true then
			DataString.Part.Anchored = true
		else
			DataString.Part.Anchored = false
		end
	
		DataString.Part.ClassName = Part.ClassName
	
		if Part:GetChildren() == true then
			DataString.Part.HasChildren = true
		else
			DataString.Part.HasChildren = false
		end
	end

Result:
Schermafbeelding 2024-07-07 141933

Note:
I forgot too change the “Part” that comes afther every “Datastring”:

Into “PartName”, but this didn’t solve the problem :confused:

Where’s the part where you print the table?

it is in a folder, the folder is in the workspace

Can you post that code snippet too please?

GetChildren returns an array not a boolean

sorry I am very new to this, what is a snippet? :sweat_smile:

It’s a small part of a script, I think @CogTheSuit’s solution might fix your problem, if not please provide the snippet where you print the array.

How can I detect if there are parts found because if I do :FindFirstChild it will just pick one right?

if #Part:GetChildren() > 0 then
--has children
end

edit: you don’t have to say if boolean then boolean = true else boolean = false end
you can just assing the condition to the boolean.
like so;

DataString.HasChildren = #Part:GetChildren() > 0
DataString.Anchored = Part.Anchored

edit:
gethcildren() returns all children in a part as an array {}.
if there are no children, the array will be empty, # gets the length of the array, if the length isn’t greater than 0, there are no children.

Is the part anchored and has children? Also, I don’t know if the HasChildren part works, but I personally would’ve used if #Part:GetChildren() > 0 then. I’ve never used if Part:GetChildren() then, so if it works, just use it.

1 Like

Hi I figgered it out. It was only the “HasChildren” that gave problems and afther I used your suggestions I got it to work. It now fully works. Thanks everyone :smile:

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