local isOn = true function on() isOn = true script.Parent.PointLight.Enabled = true script.Sound:Play() script.Parent.Parent.Lights.Light.Pointlight.Enabled = false script.Parent.Parent.Lights.Light2.Pointlight.Enabled = false script.Parent.Parent.Lights.Light3.Pointlight.Enabled = false script.Parent.Parent.Lights.Light4.Pointlight.Enabled = false script.Parent.Parent.Lights.Light5.Pointlight.Enabled = false script.Parent.Parent.Lights.Light6.Pointlight.Enabled = false script.Parent.Parent.Lights.Light7.Pointlight.Enabled = false script.Parent.Parent.Lights.Light8.Pointlight.Enabled = false script.Parent.Parent.Lights.Light9.Pointlight.Enabled = false end function off() isOn = false script.Parent.PointLight.Enabled = false script.Sound:Stop() script.Parent.Parent.Lights.Light.Pointlight.Enabled = true script.Parent.Parent.Lights.Light2.Pointlight.Enabled = true script.Parent.Parent.Lights.Light3.Pointlight.Enabled = true script.Parent.Parent.Lights.Light4.Pointlight.Enabled = true script.Parent.Parent.Lights.Light5.Pointlight.Enabled = true script.Parent.Parent.Lights.Light6.Pointlight.Enabled = true script.Parent.Parent.Lights.Light7.Pointlight.Enabled = true script.Parent.Parent.Lights.Light8.Pointlight.Enabled = true script.Parent.Parent.Lights.Light9.Pointlight.Enabled = true end function onClicked() if isOn == true then off() else on() end end script.Parent.ClickDetector.MouseClick:connect(onClicked) on()
Please help! Here is the output : 21:29:19.030 - Script 'Workspace.TARDIS .Controls.Part.Light', Line 22 - global off 21:29:19.031 - Script 'Workspace.TARDIS.Controls.Part.Light', Line 35 21:29:19.032 - Stack End 21:29:19.033 - Disconnected event because of exception
Please give me a valid explanation of why the hell this doesn't work? :(((
local isOn = true function on() isOn = true script.Parent.PointLight.Enabled = true script.Sound:Play() script.Parent.Parent.Lights.Light.Pointlight.Enabled = false script.Parent.Parent.Lights.Light2.Pointlight.Enabled = false script.Parent.Parent.Lights.Light3.Pointlight.Enabled = false script.Parent.Parent.Lights.Light4.Pointlight.Enabled = false script.Parent.Parent.Lights.Light5.Pointlight.Enabled = false script.Parent.Parent.Lights.Light6.Pointlight.Enabled = false script.Parent.Parent.Lights.Light7.Pointlight.Enabled = false script.Parent.Parent.Lights.Light8.Pointlight.Enabled = false script.Parent.Parent.Lights.Light9.Pointlight.Enabled = false end function off() isOn = false script.Parent.PointLight.Enabled = false script.Sound:Stop() script.Parent.Parent.Lights.Light.Pointlight.Enabled = true script.Parent.Parent.Lights.Light2.Pointlight.Enabled = true script.Parent.Parent.Lights.Light3.Pointlight.Enabled = true script.Parent.Parent.Lights.Light4.Pointlight.Enabled = true script.Parent.Parent.Lights.Light5.Pointlight.Enabled = true script.Parent.Parent.Lights.Light6.Pointlight.Enabled = true script.Parent.Parent.Lights.Light7.Pointlight.Enabled = true script.Parent.Parent.Lights.Light8.Pointlight.Enabled = true script.Parent.Parent.Lights.Light9.Pointlight.Enabled = true end function onClicked() if isOn == true then off() else on() end end script.Parent.ClickDetector.MouseClick:connect(onClicked) on()
I think it is because your if statement is on the same line as your else statement.