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.
Instead of deleting an object you can just set its parent to 'nil' and use it for later
local yourobj = game.Workspace:WaitForChid('Part') yourobj.Parent = nil wait(10) yourobj.Parent = game.Workspace
it works just fine for me