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
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
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 : )