I have this script that control downlights for my projects
script.Parent.Switches.DownSwitch.Value.Changed:Connect(function()
local DownLightSwitch = script.Parent.Switches.DownSwitch.Value
if DownLightSwitch.Value == 1 then
for i,v in pairs (script.Parent.DownLights:GetChildren()) do
if v.Name == "LoungeDownLight" then
v.GimbalPivot.HalogenGlobe.Light.SpotLight.Enabled = true
v.GimbalPivot.HalogenGlobe.Light.PointLight.Enabled = true
v.GimbalPivot.HalogenGlobe.Light.Beam.Enabled = true
v.GimbalPivot.HalogenGlobe.Bulb.BrickColor = BrickColor.new("Daisy orange")
v.GimbalPivot.HalogenGlobe.Bulb.Material = "Neon"
end
end
else
for i,v in pairs (script.Parent.DownLights:GetChildren()) do
if v.Name == "LoungeDownLight" then
v.GimbalPivot.HalogenGlobe.Light.SpotLight.Enabled = false
v.GimbalPivot.HalogenGlobe.Light.PointLight.Enabled = false
v.GimbalPivot.HalogenGlobe.Light.Beam.Enabled = false
v.GimbalPivot.HalogenGlobe.Bulb.BrickColor = BrickColor.new("Institutional white")
v.GimbalPivot.HalogenGlobe.Bulb.Material = "SmoothPlastic"
end
end
end
end)
basically it checks a switch if its 1 turn it on else its off
I’d like to use tween on it to make it more like halogen lights in real life
like slowly increase the brightness and the bulb colour from black to dark orange to yellow(?)
and the opposite for off
(beam in this case is just on and off cuz it’s based on the light’s brightness)
But I’m still not used to tween and it’s a bit difficult for me
Ok! I have a finished product. It was a little limited in what It could do as I can’t actually test it, but in theory, it should work. Hope it helps!
local TIME_TO_TAKE = 2 --change this to the number of seconds you want the animation to take.
local EASING_STYLE = Enum.EasingStyle.Sine --This should work for your purposes, although if you want, you can research easing styles more.
local ON_BRIGHTNESS = script.Parent.DownLights.LoungeDownLight.GimbalPivot.HalogenGlobe.Light.SpotLight.Brightness
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(TIME_TO_TAKE, EASING_STYLE, Enum.EasingDirection.InOut, 0, false, 0)
local tweenontable = {}
local tweenofftable = {}
for i,v in pairs (script.Parent.DownLights:GetChildren()) do
if v.Name == "LoungeDownLight" then
local tween1 = tweenservice:Create(v.GimbalPivot.HalogenGlobe.Light.SpotLight, tweeninfo, {["Brightness"] = ON_BRIGHTNESS})
local tween2 = tweenservice:Create(v.GimbalPivot.HalogenGlobe.Light.PointLight, tweeninfo, {["Brightness"] = ON_BRIGHTNESS})
table.insert(tweenontable, tween1)
table.insert(tweenontable, tween2)
local tween3 = tweenservice:Create(v.GimbalPivot.HalogenGlobe.Light.SpotLight, tweeninfo, {["Brightness"] = 0})
local tween4 = tweenservice:Create(v.GimbalPivot.HalogenGlobe.Light.PointLight, tweeninfo, {["Brightness"] = 0})
table.insert(tweenofftable, tween3)
table.insert(tweenofftable, tween4)
end
end
script.Parent.Switches.DownSwitch.Value.Changed:Connect(function()
local DownLightSwitch = script.Parent.Switches.DownSwitch.Value
if DownLightSwitch.Value == 1 then
for i,v in pairs(tweenontable) do
v:Play()
end
for i,v in pairs (script.Parent.DownLights:GetChildren()) do
if v.Name == "LoungeDownLight" then
v.GimbalPivot.HalogenGlobe.Light.Beam.Enabled = true
v.GimbalPivot.HalogenGlobe.Bulb.BrickColor = BrickColor.new("Daisy orange")
v.GimbalPivot.HalogenGlobe.Bulb.Material = "Neon"
end
end
else
for i,v in pairs(tweenofftable) do
v:Play()
end
for i,v in pairs (script.Parent.DownLights:GetChildren()) do
if v.Name == "LoungeDownLight" then
v.GimbalPivot.HalogenGlobe.Light.Beam.Enabled = false
v.GimbalPivot.HalogenGlobe.Bulb.BrickColor = BrickColor.new("Institutional white")
v.GimbalPivot.HalogenGlobe.Bulb.Material = "SmoothPlastic"
end
end
end
end)