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

Whats up with this script?

Asked by 9 years ago

Whats up with this script? Im trying to make it so when a brick is clicked it would turn a light on the first time the brick gets clicked it would turn the light on. And the second time it gets clicked the light would turn off here heres script

01local button = script.Parent
02local function lightOn()
03    game.Workspace.(NAMEOFBRICKHEE).(NAMEOFBRICKHERE).PointLight.Enabled = true
04    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).NAMEOFBRICKHERE = BrickColor.new("White")
05end
06 
07local function lightOff()
08    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).PointLight.Enabled = false
09    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).BrickColor = BrickColor.new("Black")
10 
11end
12button.ClickDetector.MouseClick:connect(lightOn)
13button.ClickDetector.MouseClick:connect(lightOff)

1 answer

Log in to vote
2
Answered by 9 years ago
1function onClicked()
2    --code here
3end
4script.Parent.MouseClick:connect(onClicked)
1function onClicked() --Our function
2    if script.Parent.on.Value == false then --Our if statement, to determine if the light is on/off
3        script.Parent.on.Value = true
4        script.Parent.PointLight.Enabled = true --If it is off, then it will turn the light on
5    else --Checks if the if statement is anything else other than false, so if it is true
6        script.Parent.on.Value = false
7        script.Parent.PointLight.Enabled = false --If it is on, then it will turn the light off
8end
9script.Parent.MouseClick:connect(onClicked) --Receiving the Function
Ad

Answer this question