|
| 04 Mar 2017 09:59 AM |
I've been trying to write an on/ off script using a click detector that activates/ deactivates a ParticleEmitter. But, I can't seem to figure out how to make it work. Can anyone help me? I'll post what I have below, hopefully Roblox won't censor.
script.Parent.ClickDetector.MouseClick:connect(onClicked) local sm = script.Parent.Parent.smoke
local isOn = false script.Parent.Button.Detect.MouseClick:connect(function() if On==false then isOn = true sm.ParticleEmitter.Enabled = true On=true elseif On==true then isOn = false sm.ParticleEmitter.Enabled = false On=false end |
|
|
| Report Abuse |
|
|
iiJameul
|
  |
| Joined: 11 Feb 2017 |
| Total Posts: 85 |
|
|
| 04 Mar 2017 10:05 AM |
1) You have not explained what On is you have explained to the server what IsOn is but not On.
Use local On = false
2)I do not see the need to have On and IsOn in the script.
3) ClickDetectors are buggy.
4) you should use;
Script.Parent.MouseClick:Connect(function() sm.Enabled = not sm.Enabled End
68% of people cannot script that 1% is me.
|
|
|
| Report Abuse |
|
|
|
| 04 Mar 2017 10:15 AM |
Ok so along with your changes, I tried to add some aswell, but they still do not work. What am I doing wrong?
Script.Parent.MouseClick:Connect(function() sm.Enabled = not sm.Enabled local sm = script.Parent.Parent.smoke
local On = false script.Parent.Button.Detect.MouseClick:connect(function() if On==false then sm.ParticleEmitter.Enabled = true elseif On==true then sm.ParticleEmitter.Enabled = false
end |
|
|
| Report Abuse |
|
|
|
| 04 Mar 2017 11:17 AM |
You know what is going wrong?
The fact that you call to a variable before assigning it: sm.Enabled = not sm.Enabled local sm = script.Parent.Parent.smoke |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Mar 2017 11:18 AM |
I'm also confused why he's using the 'On' variable if he's aware that the 'not' logical operator exists.
|
|
|
| Report Abuse |
|
|