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

How do I make a button that turns off and on all particle emitters in my game?

Asked by 7 years ago

I want to make a button that when you click it, it turns off particle effects and turns them on if you click it again. I have no idea how to though and I would like the responses to be descriptive like tell me what scripts to put in each part and etc.

0
No. User#6546 35 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I made this script to delete all my fixers in my game.

repeat wait() until game:GetService("ContentProvider").RequestQueueSize == 0

function RecursiveGeneric(Parent, Func, ClassLimit)
    for _, Child in pairs(Parent:GetChildren()) do
        if not ClassLimit or Child:IsA(ClassLimit) then
            Func(Child)
        end
        RecursiveGeneric(Child, Func, ClassLimit)
    end
end

RecursiveGeneric(
    workspace,
    function(part)
        if part.Name == "Fixer" then
            part:Destroy()
        end
    end,
    "BasePart", "UnionOperation"
)

script:Destroy()

The important part is this:

function RecursiveGeneric(Parent, Func, ClassLimit)
    for _, Child in pairs(Parent:GetChildren()) do
        if not ClassLimit or Child:IsA(ClassLimit) then
            Func(Child)
        end
        RecursiveGeneric(Child, Func, ClassLimit)
    end
end

This is from an endorsed weld script. So if we do this:

function RecursiveGeneric(Parent, Func, ClassLimit)
    for _, Child in pairs(Parent:GetChildren()) do
        if not ClassLimit or Child:IsA(ClassLimit) then
            Func(Child)
        end
        RecursiveGeneric(Child, Func, ClassLimit)
    end
end

function SetAllEmitters(value)
    RecursiveGeneric(
        game.workspace,
        function(emitter)
            emitter.Enabled = value
        end,
        "ParticleEmitter"
    )
end

Then just use that function somewhere later in your script, like this:

SetAllEmitters(false)
0
I also didn't notice it said "button". use the Touched event with my function. http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched Winseven4lyf 30 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago

This is simple, just insert this script in a function like this

function ToggleParticles()
        --Insert my script here
end

--Use the ClickDetector script thing here

Also, insert ClickDetector in your on and off button

Roblox has been changing so much, so I don't know what the current ClickDetector script is. Ok, now lets get into the script. All you need to do is call all your particle emmitters and add this after ParticleEmitter, .Enabled = false Example:

--Insert your part/brick name at Part
--Insert your ParticleEmmiter name in ParticleEmmiter
game.Workspace.Part.ParticleEmmiter.Enabled = false

NOTE:Make sure each brick/part is a DIFFRENT NAME or else the script might/will mess up. So basically like this

function ToggleParticles()
game.Workspace.Part1.ParticleEmmiter.Enabled = false
game.Workspace.Part2.ParticleEmmiter.Enabled = false
game.Workspace.Part3.ParticleEmmiter.Enabled = false
end

Oh, forgot to tell you to insert the script in the off button. To do the on button, do the same just with Enabled = true instead of Enabled = false. Just a example,

function ToggleParticles()
game.Workspace.Part1.ParticleEmmiter.Enabled = true
game.Workspace.Part2.ParticleEmmiter.Enabled = true
game.Workspace.Part3.ParticleEmmiter.Enabled = true
end

Hope this helps!

0
didnt work for me CatmanErik 8 — 7y
0
sure you kept up with the ClickDetector script? I haven't, so I can't tell you. SH_Helper 61 — 7y
0
I just posted a simple way SH_Helper 61 — 7y
0
can you post the entire script and do I put it in what part i want to be the button and also do I use the click detector adavanced object aswell CatmanErik 8 — 7y
View all comments (2 more)
0
Pretty sure I mentioned this, but the last script block was for the ON button and the second last script is for ON button SH_Helper 61 — 7y
0
ya but nothing is working and i tried dif things so ya CatmanErik 8 — 7y

Answer this question