Tesouro
|
  |
| Joined: 19 Dec 2010 |
| Total Posts: 1284 |
|
|
| 01 Jul 2013 08:28 PM |
I need some help with this. The following script I made doesn't work, I don't know why (and the output says nothing). I have BoolValue called "On" and the brick which has it, the Script, a SpotLight and a ClickDetector. When you click the brick, it supposed to turn off the spotlight if its on and turn on if its off, but it doesn't. Can anyone explain this?
-- On = script.Parent.On.Value function onClick(hit) if On == true then do script.Parent.SpotLight.Enabled = false On = false end end if On == false then do script.Parent.SpotLight.Enabled = true On = true end end end script.Parent.ClickDetector.MouseClick:connect(onClick) --
p.s: I've tried to make it print something instead of disabling the spotlight, and it worked! but why it doesn't work as I want?? |
|
|
| Report Abuse |
|
|
spearman2
|
  |
| Joined: 28 May 2010 |
| Total Posts: 2938 |
|
|
| 01 Jul 2013 08:32 PM |
On = script.Parent:FindFirstChild("On").Value
function onClick(hit) if On == true then do script.Parent.SpotLight.Enabled = false On = false elseif On == false then do script.Parent.SpotLight.Enabled = true On = true end end script.Parent.ClickDetector.MouseClick:connect(onClick) |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:34 PM |
On = script.Parent:FindFirstChild("On")
function onClick(hit) script.Parent.SpotLight.Enabled = not script.Parent.SpotLight.Enabled On.Value = not On.Value end script.Parent.ClickDetector.MouseClick:connect(onClick) |
|
|
| Report Abuse |
|
|
spearman2
|
  |
| Joined: 28 May 2010 |
| Total Posts: 2938 |
|
|
| 01 Jul 2013 08:35 PM |
On = script.Parent:FindFirstChild("On")
function onClick(hit) if On.Value == true then script.Parent.SpotLight.Enabled = false On = false elseif On.Value == false then script.Parent.SpotLight.Enabled = true On = true end end script.Parent.ClickDetector.MouseClick:connect(onClick) |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:40 PM |
| Mine is way more efficient. |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:43 PM |
^ Yes, but can he understand it? In my eyes, you're not helping someone learn if they can't understand what you did to their script. |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:43 PM |
On = script.Parent.On script.Parent.ClickDetector.MouseClick:connect(function() script.Parent.SpotLight.Enabled = not script.Parent.SpotLight.Enabled On.Value = not On.Value end)
Checkmate. Just simplified yours even more. |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:45 PM |
Maybe there's something wrong with your spotlight, and not the script. I've always found spotlights a bit fussy. Make sure it's pointed in the right direction, all the properties are in check, etc. |
|
|
| Report Abuse |
|
|
|
| 01 Jul 2013 08:48 PM |
Oh duh. You have way to many ends, and some extra do's.
On = script.Parent.On.Value function onClick(hit) if On == true then -- Don't need these silly 'do's' here! script.Parent.SpotLight.Enabled = false On = false end -- this end closes teh if statement above --end--You don't need this guy, it closes the function before it's finished! if On == false then script.Parent.SpotLight.Enabled = true On = true end -- this end closes the if statement above end -- This end closes the function --end--This end isn't closing anything! script.Parent.ClickDetector.MouseClick:connect(onClick) |
|
|
| Report Abuse |
|
|
Tesouro
|
  |
| Joined: 19 Dec 2010 |
| Total Posts: 1284 |
|
|
| 02 Jul 2013 08:19 AM |
Oh, is it? Hhmm.. I thought it was a bit weird there, but it told me to put an end there. But there is no problem in the spotlight, I've tried to change other stuff, but didn't work too. |
|
|
| Report Abuse |
|
|
Tesouro
|
  |
| Joined: 19 Dec 2010 |
| Total Posts: 1284 |
|
| |
|
Tesouro
|
  |
| Joined: 19 Dec 2010 |
| Total Posts: 1284 |
|
|
| 02 Jul 2013 08:34 AM |
| AH, I tried to change the second IF for an ELSE and worked! |
|
|
| Report Abuse |
|
|
Tesouro
|
  |
| Joined: 19 Dec 2010 |
| Total Posts: 1284 |
|
| |
|