In the future, make sure your code is in a code block. It's that little blue dot that says 'Lua' in it, like this:
on = true
local bulb1 = game.Workspace.Light_Model.Light.PointLight.Enabled
function onClick()
if bulb1 == true then
on = false
elseif bulb1 == false then
on = true
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
I will assume that you want to turn the light on and off when clicked. This is simple to do, and just takes a little rearranging of your code.
local on = true
local bulb1 = game.Workspace.Light_Model.Light.PointLight
Using local variables for each makes it easier to read and less laggy. Also notice that I set bulb1 to the pointlight, not the pointlight's Enabled property. This is because when you set a variable to an instance's property, the variable becomes whatever the property is at the time the variable was defined. It will not change if the property changes, and you can not change the property by changing the variable.
if on == true then
on = false
bulb1.Enabled = false
elseif on == false then
on = true
bulb1.Enabled = false
end
Read this a few times, I hope it makes sense, because I'm not sure how to explain it further. If on is true, we turn the light off. If on is false, we turn the light on. Simple.
Hope I helped!
1 comment
No, you connect it to the ClickDetector. http://wiki.roblox.com/index.php?title=MouseClick_(Event)