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

How to continuously loop through a model's part's until certain item is found?

I feel like the title is too long, but here's what I hope my code would do:

Actually, before I start, I would like to note this is a plugin, as I'm not sure if that will help or not. . Anyway, I hope my code would loop through a model's part's until we find the specified item (in my case, a weld), if the specified item is not there, we look through the item INSIDE that part, which is where the loop will come in.

Here is what I currently have set up, and it is saved as a LOCAL plugin, and is located in a Folder in ServerScriptService. (PS: I have never made a plugin before so I bet there will be a few mistakes in the code)

local Selection = game:GetService("Selection")
local toolbar = plugin:CreateToolbar("Delete Welds")

local removeWeldPluginButton = toolbar:CreateButton("Destroy weld", "Destroy existing welds in model", "rbxassetid://348033683") -- Create button for Plugin tab in Toolbar

removeWeldPluginButton.Click:Connect(function() -- When the button is clicked

	for _, object in pairs(Selection:Get()) do -- Look for the objects that are selected
		if object:IsA("Model") then 
			-- Not sure what to put here just yet, but I can count on you!
		elseif object:IsA("BasePart") then
			-- Same deal here... I wish I could provide more than this, I am truly sorry.
		elseif object:IsA("Weld") then
			object:Destroy() -- Destroy the weld
		end
	end
	
end)

I have just found the solution! Instead of looping through it, I used :GetDescendants()! And now another problem, how would I undo a deleted object?

As always, if you would like more information, please ask, and I will provide.

1 answer

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