Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Is there an error in output?

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 ''

2 answers

✓ Accepted answer

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

12 comments

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)

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

0

@DanzLua Players.DerpzGamez.PlayerGui.SSJ Gui.SSJGui.Kaioken.Kaioken:1: 'then' expected near 'is'

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.

0

Oops, nevermind. I forgot to change the bit that said "NAME OF PARTICLE EMITTE"

0

...Nope. Still duplicates the effect.

0

@DerpzGamez ah.. can you edit the question by adding below the original what you have atm

0

Edited it.

0

@DerpzGamez is it in a localscript?

0

Yes.

0

@DerpzGamez error?

0

Nope

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.