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

Help with Light Button Script?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago
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)
Ad

Answer this question