I am attempting to make a script to Enable and disable particles (there are 24 particle emitters) from a part by clicking a nob, but it's not working. Could you please help? Thanks in advance!
function shower()
local nob = script.Parent.HeadandNob.Nob
local head = script.Parent.HeadandNob.HEad
local pe = head.one, head.two, head.three, head.four, head.five, head.six. head.seven. head.eight. head.nine, head.ten, head.eleven, head.twelve, head.thirteen, head.fourteen, head.fifteen, head.sixteen, head.eighteen, head.nineteen, head.twenty, head.twentyone, head.twentytwo, head.twentythree, head.twentyfour
local state = script.Parent.Value
if state.Value == false
then state.Value = true
pe.Enabled = true
else
state.Value = false
pe.Enabled = false
end
end
script.Parent.HeadandNob.Nob.ClickDetector.MouseClick:connect(shower)

13 comments
Thank you for responding! I am still learning the Lua code so I'm not exactly certain about functions and such. Am I suppose to use this code exactly? Because I tried it and it's not working
Yes, this code was supposed to be an exact solution. Functions are ways of defining chunks of code that you want to reuse with differentiated outcomes. You define a function with "parameters", these parameters are called "arguments" when the function is called. So in the example above "bool" on line 6 is equivalent to "false" on line 16, and "true" on line 18.
Do you have any errors in the output? Will help me determine what could be wrong :)
Thank you so much for explaining! Yes, in the console log it says 'head is not a valid member of ParticleEmiter'
Make sure you're indexing the object correctly on line 2 :)
Yupp, head is located in the Shower model in HeadandNob. Is there anything else that could be preventing the script from working?
Indexing your hierarchy is case-sensitive so make sure everything is spelled correctly. You indexed
HEadfromscript.Parent.HeadandNobwhich could have been meant to beHeadI checked the capitalization of everything and there was a mistake where I capitalized head when I meant to lowercase it. I changed this in the script and it still doesn't seem to be working
Error update? :) They help alot.
Okay, it says 'head is not a valid member of ParticleEmitter' and I don't know if this has something to do with it, but it also says 'startScript re-entrancy has exceeded 3'
That's the same error as last time mate are you positive you fixed?
Yeah I rechecked everything, and I still don't know what I'm doing wrong :(
I figured it out. I had to take the arrays off and give each pe (Particle Emitter) it's own local