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

How would I allow a player to toggle a particle effect via Gui?

Asked by 7 years ago
Edited 7 years ago

I'm currently in the process of trying to make a gui that allows players to toggle transformations from Dragon Ball Z. I'm currently working on the Kaioken, which is just a red aura. However, what I seem to have so far does not seem to be working

So I ask, is this script correct?

script.Parent.MouseButton1Click:connect(function()
    if jun.Character.Torso:findFirstChild("PwnFire") == nil then
    local fr = game.lighting.ParticleEmitterKaioken:clone()
    fr.Parent = jun.Character.Torso
end

EDIT: I have since edited the script with the advice of others, however. Now the problem is it doesn't toggle the particles, but rather duplicates them.

Here's the new script.

local jun = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
    if jun.Character.Torso:findFirstChild("PwnFire") == nil then
        local fr = game.lighting.ParticleEmitterKaioken:clone()
        fr.Parent = jun.Character.Torso
    end
    if jun.Character.Torso["ParticleEmitterKaioken"].Enabled==true then
        jun.Character.Torso["ParticleEmitterKaioken"].Enabled=false
    else
        jun.Character.Torso["ParticleEmitterKaioken"].Enabled=true
    end
end)
0
Is there an error in output? RedPandaEmperor 45 — 7y
0
It says: 20:00:06.912 - Players.DerpzGamez.PlayerGui.SSJ Gui.SSJGui.Kaioken.Kaioken:5: 'end' expected (to close 'function' at line 1) near '<eof>' DerpzGamez 6 — 7y

2 answers

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Firstly your button click event is incomplete, you forgot to add end) the end on line 5 ends the if statement so it should look like this

script.Parent.MouseButton1Click:connect(function()
    if jun.Character.Torso:findFirstChild("PwnFire") == nil then
        local fr = game.lighting.ParticleEmitterKaioken:clone()
        fr.Parent = jun.Character.Torso
    end
end)

Next it's just a matter of changing the bool value of the particle emitter depending on what its current value is

script.Parent.MouseButton1Click:connect(function()
    if jun.Character.Torso:findFirstChild("PwnFire") == nil then
        local fr = game.lighting.ParticleEmitterKaioken:clone()
        fr.Parent = jun.Character.Torso
    end
    if jun.Character.Torso["NAME OF PARTICLE EMITTE"].Enabled==true then
        jun.Character.Torso["NAME OF PARTICLE EMITTE"].Enabled=false
    else
        jun.Character.Torso["NAME OF PARTICLE EMITTE"].Enabled=true
    end
end)

This now makes it so that if its on it will turn off and if its off it will turn on

0
Tried that, getting: 20:03:50.271 - Players.DerpzGamez.PlayerGui.SSJ Gui.SSJGui.Kaioken.Kaioken:2: attempt to index global 'jun' (a nil value) DerpzGamez 6 — 7y
0
@DerpzGamez You are getting that error because the variable jun isn't defined I'm guessing that jun is the player so at the top of the script just add local jun = game.Players.LocalPlayer if this is a localscript DanzLua 2879 — 7y
0
@DanzLua Players.DerpzGamez.PlayerGui.SSJ Gui.SSJGui.Kaioken.Kaioken:1: 'then' expected near 'is' DerpzGamez 6 — 7y
0
Added the "if this is a local script too" XD Although now the only problem is, pressing the button again doesn't turn the effect off but rather duplicates it. DerpzGamez 6 — 7y
View all comments (8 more)
0
Oops, nevermind. I forgot to change the bit that said "NAME OF PARTICLE EMITTE" DerpzGamez 6 — 7y
0
...Nope. Still duplicates the effect. DerpzGamez 6 — 7y
0
@DerpzGamez ah.. can you edit the question by adding below the original what you have atm DanzLua 2879 — 7y
0
Edited it. DerpzGamez 6 — 7y
0
@DerpzGamez is it in a localscript? DanzLua 2879 — 7y
0
Yes. DerpzGamez 6 — 7y
0
@DerpzGamez error? DanzLua 2879 — 7y
0
Nope DerpzGamez 6 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You forgot to end the function lol

script.Parent.MouseButton1Click:connect(function()
    if jun.Character.Torso:findFirstChild("PwnFire") == nil then
    local fr = game.lighting.ParticleEmitterKaioken:clone()
    fr.Parent = jun.Character.Torso
    end
end)

Answer this question