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

Whats up with this script?

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

✓ Accepted answer
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

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