Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

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

Normal

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

Can anyone help?

1 comment

0

Are you getting any errors? Because I just tested it and it worked fine.

1 answer

✓ Accepted answer

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):

function onTouch()
	if script.Parent.Parent.LightPart.Range==0 then
		script.Parent.Parent.LightPart.Range=8
	elseif script.Parent.Parent.LightPart.Range==8 then
		 script.Parent.Parent.LightPart.Range=0
	end
end
script.Parent.ClickDetector.MouseClick:connect(onTouch)

Version 2(Uses both buttons):

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.