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

My light switch script wont work and the roblox Forum wont help?

Asked by 7 years ago

Basically, I have 2 buttons, one to make the lights range normal and once to make the lights range 0. These are the 2 scripts.

0

1function onClicked()
2script.Parent.Parent.LightPart.PointLight.Range = 0
3end
4script.Parent.ClickDetector.MouseClick:connect (onClicked)

Normal

1function onClicked()
2script.Parent.Parent.LightPart.PointLight.Range = 8
3end
4script.Parent.ClickDetector.MouseClick:connect (onClicked)

Can anyone help?

0
Are you getting any errors? Because I just tested it and it worked fine. roblox99456789 104 — 7y

1 answer

Log in to vote
0
Answered by
iRexBot 147
7 years ago
Edited 7 years ago

I've have not tested this scripted but I am gonna destroy the 2nd button so both buttons can be in 1 script also on line 4 for both you left a space between the connect. That might be the reason

Version 1(Uses 1 button only):

1function onTouch()
2    if script.Parent.Parent.LightPart.Range==0 then
3        script.Parent.Parent.LightPart.Range=8
4    elseif script.Parent.Parent.LightPart.Range==8 then
5         script.Parent.Parent.LightPart.Range=0
6    end
7end
8script.Parent.ClickDetector.MouseClick:connect(onTouch)

Version 2(Uses both buttons):

1function onClicked()
2script.Parent.Parent.LightPart.PointLight.Range = 8
3end
4script.Parent.ClickDetector.MouseClick:connect(onClicked)
1function onClicked()
2script.Parent.Parent.LightPart.PointLight.Range = 0
3end
4script.Parent.ClickDetector.MouseClick:connect(onClicked)

You messed up on version 2 with the connect having a space.

Ad

Answer this question