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

How do i can make a For to delete all workspace items with same name?

Asked by 2 years ago
Edited 2 years ago

Im making a script that spawn a Throne in front of me, but sometimes when i die, it bug and i can spawn 2 thrones a time, i made a script that "when i press B, it spawn, when i press B again, it :Destroy", but when existe 2 of it, my script only destroy 1, i made a for to search all Workspace items with the Throne name, but its not working, wt im making wrong?

For Script:

if throneExists then
        for _, v in pairs(game.Workspace:FindFirstChild("BaragganThroneRemote")) do
            v:Destroy()
            wait(.1)
        end
    else
        local clone = model:Clone()

        clone.Parent = workspace
        clone:PivotTo(character.HumanoidRootPart.CFrame * CFrame.new(0, 1.3, 0) * CFrame.Angles(math.rad(180), math.rad(90), math.rad(0)))
    end
0
Idk how you set up the workspace, but assuming you have a folder with all the parts of the throne, then you simply just reference the folder and folder:GetChildren():Destroy(). This is not an exact solution but you try something similar to this Shampoo02496 2 — 2y
0
or you can select all the parts of the throne and hit Ctrl + G to make it a model and make your script summon and destroy the model Shampoo02496 2 — 2y
0
its already a model, its that "BaragganThroneRemote", i want a For that keep searching if there's something named "BaragganThroneRemote" in the Workspace and If Yes, destroy it. Ariirael 15 — 2y
0
@Shampoo02496 - GetChildren() returns an array, not an instance object. Calling Destroy() on GetChildren() will throw an invalid property error. ScriptGuider 5640 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

Add a ":GetChildren()" to get all the Childs of a Parent

for i,v in pairs (game.Workspace:FindFirstChild("BaragganThroneRemote"):GetChildren()) do
v:Destroy()
wait(0.1)
end
Ad

Answer this question