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

How would I remove all the particles from a part if they have diferent names?

Asked by 7 years ago
Edited 7 years ago

I have the clicking script but I need to be able to remove all of the particles in the part and im asking for ONE line of code im not requesting a script i just want to know a way to destroy all of one thing for example say i had Three particleEmitters in workspace and they were named 1 2 and 3 could i just remove all the parts? and if so how? But say there were 6 1s 4 2s and 8 3s how would i remove all of them at once without knowing how much of each there are

local click = game.Players.LocalPlayer
local adorn = workspace.ParticleGUI

script.Parent.Parent.Adornee = adorn;

local function OnClicked()
    click.Character.HumanoidRootPart -- missing part because i dont know what to do there
end

script.Parent.MouseButton1Click:connect(OnClicked)
0
I might need to use WaitForChild but I am not experienced with WaitForChild DreamSkyHigh 30 — 7y
0
It would be helpful if you showed the code Prestory 1395 — 7y
0
Show code BlackOrange3343 2676 — 7y
0
Im asking for one line of code ;-; DreamSkyHigh 30 — 7y

3 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

Answering based on information you supplied in the Community Chat

In order to destroy all objects of a particular ClassType, you need to take advantage of generic for loops.

Generic for loops take in a table, and iterate through it. You can iterate through the descendants of your object using the GetChildren function, and use the IsA function to check the ClassType of the child. If it is a ParticleEmitter then use the Destroy function.

local m = workspace.Model --This is what you're iterating through.

function clean(model)
    for _,v in next,model:GetChildren() do --Generic for loop
        if v:IsA("ParticleEmitter") then --If it's a ParticleEmitter
            v:Destroy() --Destroy it.
        end
    end
end

clean(m)

Now, the script above would only eradicate direct children of the model. Meaning children of children could potentially not be affected. In order to access all children of the model, you need to use recursion.

Recursion is basically the concept of calling a function inside of itself. You can use this to affect the whole model like so:

local m = workspace.Model --What you're iterating through

function clean(model)
    local function affect(M)
        for _,v in next,M:GetChildren() do --iterate through children
            if v:IsA("ParticleEmitter") then --if it's an emitter, destroy
                v:Destroy()
            end
            if #v:GetChildren() > 0 then --if it has children,
                affect(v) --recurse the function on the child.
            end
        end
    end
    affect(model)
end

clean(m)
Ad
Log in to vote
0
Answered by 7 years ago

Thank you for posting your code, currently as I read your question, your trying to figure out how to delete/remove 3 parts.

This will be kinda like a tutorial.

First, you will need 3 parts that you want to delete. As an example let's just name them "Part1", "Part2", and "Part3". Now you will need to make sure all these parts have their settings correct.

  1. Make sure the part's CanCollide and Anchored settings are both true

Now, you will need another part, Name it "Button". Right Click on Button and insert a ClickDetector.

Now add a Script to the ClickDetector so that the Button is the part, the ClickDetector is inside of the Part and the script is inside of the ClickDetector.

Now open up the script and delete "Print("Hello World")".

starter with variables, I won't be explaining variables but in other words, variables are to help you define objects and makes scripting easier.

Let's define the ClickDetector, Part1, Part2 and Part3.

This is how it should look like:

local Clicker = script.Parent
local Part1 = game.Workspace:WaitForChild("Part1")
local Part2 = game.Workspace:WaitForChild("Part2")
local Part3 = game.Workspace:WaitForChild("Part3")

Now we add the Click Event

This is how it should look like:

local Clicker = script.Parent
local Part1 = game.Workspace:WaitForChild("Part1")
local Part2 = game.Workspace:WaitForChild("Part2")
local Part3 = game.Workspace:WaitForChild("Part3")

Clicker.MouseClick:connect(function()

end)

Now we want to make it so that you destroy the 3 parts

so lastly this is how everything should look like:

local Clicker = script.Parent
local Part1 = game.Workspace:WaitForChild("Part1")
local Part2 = game.Workspace:WaitForChild("Part2")
local Part3 = game.Workspace:WaitForChild("Part3")

Clicker.MouseClick:connect(function()
    Part1:Destroy()
    Part2:Destroy()
    Part3:Destroy()
end)

Now go try clicking the part named "Button" and see if it works. Please accept answer and upvote if helped and worked.

Log in to vote
-1
Answered by
iRexBot 147
7 years ago

This is not a script request site.

0
you arent very bright im asking for one line of code I dont know how to destroy all of one thing DreamSkyHigh 30 — 7y

Answer this question