Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this SpotLight script work?

Asked by 10 years ago

For some strange reason it is highlighting else as being red... Please help!

function onClick()
script.Parent.Parent.Parent.Lights.Lamp.SpotLight.Brightness=100
else
script.Parent.Parent.Parent.Lights.Lamp.SpotLight.Brightness=0
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

1 answer

Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
10 years ago

It is highlighted because there is no "If" statement.

Every "else" needs an "if" to go along with it.

I would help you finish the script, but I am unsure what you are trying to accomplish.

Example of if and else:

if x < 8 then
x = x + 5
else
x = x - 5
end

In order to get what you want done, try something like this...

function onClick()
--The following if statement will check the brightness of the spotlight
if script.Parent.Parent.Parent.Lights.Lamp.SpotLight.Brightness == 100 then
-- If the spotlight is already 100, then it will bring it down to 0
script.Parent.Parent.Parent.Lights.Lamp.SpotLight.Brightness=0
else -- If the spotlight is anything else, it will set it to 100
script.Parent.Parent.Parent.Lights.Lamp.SpotLight.Brightness=100
end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

0
I want the spotlight to go off and on on the click of a button WelpNathan 307 — 10y
0
In the edit, I added what I think would help. I have not tested it however. If you notice though, there is now an if and else statement that checks the birghtness of the spotlight and changes it accordingly. Also, don't forget to add an "end" after using these statements. Necrorave 560 — 10y
Ad

Answer this question