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

Help with Light Button Script?

i need help to get the button when tapped it will turn on some light/neon And when i click twice the neon disapare

local model = script.Parent.Parent
while true do
script.Parent.ClickDetector.MouseClick:connect(function()
model.children.transparency = 0
end)

1 answer

local LightOn = false

local Light = script.Parent.Parent

script.Parent.ClickDetector.MouseClick:connect(function()
	if LightOn then
		LightOn = false
		Light.children.Transparency = 1
	else
		LightOn = true
		Light.children.Transparency = 0
	end
end)

By using the variable "LightOn", the script will alternate between on and off every time that you click, and manage the light based on the value. I presume "children" is the name of the part, and you didn't mean "GetChildren()", in which case I'd use this code:

local LightOn = false

local Light = script.Parent.Parent

Alternate = function(Trans)
	for _,Part in pairs(Light:GetChildren()) do
		Part.Transparency = Trans
	end
end)

script.Parent.ClickDetector.MouseClick:connect(function()
	if LightOn then
		LightOn = false
		Alternate(1)
	else
		LightOn = true
		Alternate(0)
	end
end)

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