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

Enabling ParticleEmitters Issue?

Asked by 9 years ago

Trying to script some particle emitters to enable and disable depending on if a boolvalue in the workspace is true or false. For some reason it doesn't work, I have the boolvalue set to turn true or false depending on the button pressed in the workspace, which works fine, but the particle emitters dont enable themselves when I press the button. Not sure what I'm doing wrong. Is ROBLOX just not able to do it or is it me?

if game.Workspace.ConfettiEnabled.Value==true then
    script.Parent.Enabled=true
else
    script.Parent.Enabled=false
end
0
You did not set it up to fire a second time, or to fire when the Button is pressed. TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

I'm assuming that's the only code in your script. If it is, your problem is that the code is only checking if the bool value is true once, and then never checking again. So if you change it, the script won't detect it. In order to do that, you have to use the Changed event.

Basically what the Changed event does is that it fires whenever a property of the object that it's connected to changes. So you can use that with this bool value to check whether or not the value is true or false.

You would use it like this:

game.Workspace.ConfettiEnabled.Changed:connect(function() --This will call the function in the parenthesis every time the Changed event is fired
    if game.Workspace.ConfettiEnabled.Value==true then --Check if the bool value is true
        script.Parent.Enabled=true
    else
        script.Parent.Enabled=false
    end
end)

Hope this helped!

Further resources: Changed

Ad
Log in to vote
2
Answered by
LostPast 253 Moderation Voter
9 years ago

if then only checks once right when the game starts. If you are checking for a Bool Value to be changed use;

game.Workspace.ConfettiEnabled.Changed:connect(function() --This will call the function in the parenthesis every time the Changed event is fired
    if game.Workspace.ConfettiEnabled.Value==true then --Check if the bool value is true
        script.Parent.Enabled=true
    else
        script.Parent.Enabled=false
    end
end)

Changed checks for when the children or properties of ConfettiEnabled are changed. If so it will run the program.

Hope This Helps : )

0
Did turbo copy your answer, or did you copy his?? Operation_Meme 890 — 9y
0
Nobody copied any answers, they just posted at the same time. However, you both could shorten your scripts though so you could just set script.Parent.Enabled to be the Value when the event fires instead of having to use more lines for the if statement. Spongocardo 1991 — 9y
0
I was writing my answer and when I posted it, I saw that he posted an answer as well. It was purely coincidental TurboFusion 1821 — 9y

Answer this question