Plugin alternates working and not working properly

I’m making a new plugin and I had a previous issue that I solved myself so I deleted that topic, but I’ve come across another issue, and I’m not quite sure how to solve it.

Basically, this plugin groups stuff by ClassName, but with my test files (shown below), it alternates between grouping correctly and incorrectly (shown below).

image


image

image

How would I go about fixing it? The relevant portion of the script is here:

for _, child in ipairs(selectedObjects) do
		local array = child:GetChildren()
		
		for x, descendant in ipairs(array) do
			if descendant:GetAttribute("GroupMe_Ignore") == true then
				print("GroupMe: File was not able to be grouped (file name '" .. descendant:GetFullName() .. "')")
			else
				local classtype = descendant.ClassName
				if child:FindFirstChild(classtype) and child:FindFirstChild(classtype).ClassName == "Folder" then
					descendant.Parent = child:FindFirstChild(classtype)
				else
					local folder = Instance.new("Folder", child)
					folder.Name = classtype
					folder:SetAttribute("GroupMe_Ignore", true)
					descendant.Parent = folder
				end
			end
		end
	end

I solved it (sorta). There will be a better way but I decided to check the array within checking the array for any instances that have the same name as the classtype of the currently selected instance. If it does, then it renames it to ease confusion.

For folders, I can’t really do this simply because of obvious reasons.

for i, v in ipairs(array) do
					if v.Name == classtype then
						if v:IsA("Folder") then
						else
							v.Name = v.Name .. ".old"
						end
					end
				end
for _, child in ipairs(selectedObjects) do
	local array = child:GetChildren()
	
	for x, descendant in ipairs(array) do
		if descendant:GetAttribute("GroupMe_Ignore") == true then
			print("GroupMe: File was not able to be grouped (file name '" .. descendant:GetFullName() .. "')")
		else
			local group = descendant:GetAttribute("GroupMe_Group")
			if group == nil then
				print("GroupMe: Object '" .. descendant:GetFullName() .. "' does not have a group specified.")
			else
				if child:FindFirstChild(group) and child:FindFirstChild(group).ClassName == "Folder" then
					descendant.Parent = child:FindFirstChild(group)
				else
					local folder = Instance.new("Folder", child)
					folder.Name = group
					folder:SetAttribute("GroupMe_Ignore", true)
					descendant.Parent = folder
				end
			end
		end
	end
end

This script iterates over each child of the selectedObjects array, and for each child, it iterates over each descendant of the child. It checks if the descendant has the custom property “GroupMe_Group” specified, and if so, it groups the descendant with other objects in the same group.

If the descendant does not have a group specified, the script prints a warning message to the console. If the group does not already exist as a folder in the child, the script creates a new folder with the group name and sets a custom attribute on the folder to ignore it during grouping.

Without more context and information, it’s hard to provide a specific solution to your issue. I would recommend debugging your code by printing out the values of variables at different points in the script to identify where the issue might be occurring. You could also try using a debugger to step through your code and see how the objects are being grouped.

Just completely makes the script not work unfortunately, the plugin relies on getting the children of what’s selected to group stuff by ClassName.

image

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