How to make a light that flickers while on but does nothing while is off

Ok, what would be the best way of fixing these issues? I sent you the exact models and script, if you don’t mind you can download those and import them into Studio to debug the issues there. I also provided a video showing the current issue I’m having with the lastest script we made.

What is the Sound? I mean, why the light should change its properties based on its volume? its not music right? its ambience? noises?

The spot light should have its properties changes, as well as the transparency of the part that the spotlight is a child of to give that flickering light effect. Also yes, the sound is just a light flickering noise. You can pull a random one from the tool box if the one I sent you isn’t working.

The material changes like Neon the SmoothPlastic is when the light is off and on. The light wouldn’t look off if the light (part) was still Neon. You know what I mean?

The switch logic in this script Im editing works as intended, but, I need to listen the “flickering noise” in order to know how to manipulate the properties of the light.

In this example Im using music, and based on “high volume” cause “high lighting”, and the opposite for lower volumes.

Give me an ID of a roblox sound that sounds very similar to the one you are using.

I don’t have an ID that sounds similar, but I have the audio file. You’re more than welcome to download this and upload it into studio as well.

The more volume the less light? or the opposite? the more volume the brighter light?

The louder the volume the more dim the light will be. The opposite would be quiet would be bright.

You can use a simple formula such as Light.Angle = 1 / currentLoudness. This would mean that the louder (higher) the PlaybackLoudness is, the lower the angle is, making it dim - I haven’t worked with lights or this kinda stuff so, I might be wrong…

Look, this script is decreasing the lighting based on the amount of volume of the sound:

local RunService = game:GetService("RunService")

local Light = workspace.Office.Light.Bulb.SurfaceLight
local Sound = workspace.Office.Light.FlickeringLightSound

local lightPrompt = game.Workspace.Office.Lightswitch.Main:WaitForChild("LightSwitchPrompt")

local HeartBeatConn

local lightStatus = false

local OriginalLightAngle = 90
local OriginalTrasparency = 0

local function HandleLight()
	if not lightStatus then
		warn("on")
		lightStatus = true
		
		Sound:Play()
		Light.Parent.Material = Enum.Material.Neon
		Light.Enabled = true

		HeartBeatConn = RunService.Heartbeat:Connect(function()
			print("flickering")
			Light.Angle = OriginalLightAngle - (Sound.PlaybackLoudness * 0.8)
			Light.Parent.Transparency = OriginalTrasparency + (Sound.PlaybackLoudness/500)
		end)
	else
		warn("off")
		lightStatus = false

		Light.Parent.Material = Enum.Material.Plastic
		Light.Enabled = false
		Sound:Stop()
		
		HeartBeatConn:Disconnect() -- stop the heartbeat updating
	end
end

lightPrompt.Triggered:Connect(HandleLight)
HandleLight()

image
I believe this does the same thing…

No okay, hold on…
Alright, I got it now, but this is kind of confusing.

A video

Ok, we are on a good track now. That worked for me, now what about the physical switch moving up and down corresponding to the light being on or off? Right now it just stays in this position.
image

Thats an easy part, just change the CFrame of the part

I think a ClickDetector would work, and using CFrame.Angles you can change the switch’s physical position… Orientation, I mean.

Why not just change the orientation using Vector3 like I did before?

CFrame contains the angle of the part, yeah orientation could work, but I love to use CFrame. Depends on you

Ok, should I do that in a separate script?

Vector3 does not hold orientation, it merely stores the position of an object within a 3D world. CFrames hold their position and their orientation, so it’s better.

Of course not, should be included inside the same function of the switch

Oh ok, thank you for clarifying that.