Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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)

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

Log in to vote
0
Answered by 3 years ago

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

0
Thank you for your help! LikeableEmmec 470 — 3y
Ad

Answer this question