How to continuously loop through a model's part's until certain item is found?
Asked by
3 years ago Edited 3 years ago
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)
01 | local Selection = game:GetService( "Selection" ) |
02 | local toolbar = plugin:CreateToolbar( "Delete Welds" ) |
04 | local removeWeldPluginButton = toolbar:CreateButton( "Destroy weld" , "Destroy existing welds in model" , "rbxassetid://348033683" ) |
06 | removeWeldPluginButton.Click:Connect( function () |
08 | for _, object in pairs (Selection:Get()) do |
09 | if object:IsA( "Model" ) then |
11 | elseif object:IsA( "BasePart" ) then |
13 | elseif object:IsA( "Weld" ) then |
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.