generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Whoops

Previous Thread :: Next Thread 
Tesouro is not online. 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 is not online. 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
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
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 is not online. 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
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
01 Jul 2013 08:40 PM
Mine is way more efficient.
Report Abuse
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
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
dennis96411 is not online. dennis96411
Joined: 06 Mar 2009
Total Posts: 1079
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
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
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
dog456pop248 is not online. dog456pop248
Joined: 24 Aug 2008
Total Posts: 3977
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 is not online. 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 is not online. Tesouro
Joined: 19 Dec 2010
Total Posts: 1284
02 Jul 2013 08:22 AM
Thanks dog.
Report Abuse
Tesouro is not online. 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 is not online. Tesouro
Joined: 19 Dec 2010
Total Posts: 1284
02 Jul 2013 08:35 AM
herpderp
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image