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 8 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

local button = script.Parent
local function lightOn()
    game.Workspace.(NAMEOFBRICKHEE).(NAMEOFBRICKHERE).PointLight.Enabled = true
    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).NAMEOFBRICKHERE = BrickColor.new("White")
end

local function lightOff()
    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).PointLight.Enabled = false
    game.Workspace.(NAMEOFBRICKHERE).(NAMEOFBRICKHERE).BrickColor = BrickColor.new("Black")

end
button.ClickDetector.MouseClick:connect(lightOn)
button.ClickDetector.MouseClick:connect(lightOff)


1 answer

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

Answer this question