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

You can change the Orientation of any part, and you can only use a Vector3. Vector3 is not a position, is coordinates, can be used for Orientation or Position

Eh, I don’t build, I only use UDims. However I do prefer to use CFrame for this kind of stuff.
Vectors are coordinates, thanks for correcting, and yes, you can change the orientation using that, but I do prefer using CFrame.Angles for object orientation.

I agree, CFrame is way better than changing Positions or Orientation, its more flexible and contains everything inside the CFrame, depends on @NotoriousProphecy using Vector3 for Orientation or CFrame. Im in love with CFrames xD

It works! I used Vector3 because CFrame didn’t work. Thank you so much though!

Final Script:

local RunService = game:GetService("RunService")

local Light = workspace.Office.Light.Bulb:WaitForChild("SpotLight")
local Sound = workspace.Office.Light:WaitForChild("FlickeringLightSound")

local Switch = workspace.Office.Lightswitch:WaitForChild("Switch")

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

local HeartBeatConn

local lightStatus = false

local OriginalLightAngle = 180
local OriginalTrasparency = 0

local function HandleLight()
	if not lightStatus then
		lightStatus = true

		Sound:Play()
		Light.Parent.Material = Enum.Material.Neon
		Light.Enabled = true
		
		Switch.Orientation = Vector3.new(35, 0, 0)

		HeartBeatConn = RunService.Heartbeat:Connect(function()
			Light.Angle = OriginalLightAngle - (Sound.PlaybackLoudness * 0.5)
			Light.Parent.Transparency = OriginalTrasparency + (Sound.PlaybackLoudness/10)
		end)
	else
		lightStatus = false

		Light.Parent.Material = Enum.Material.Plastic
		Light.Enabled = false
		Sound:Stop()
		
		Switch.Orientation = Vector3.new(55, 180, 180)

		HeartBeatConn:Disconnect() -- stop the heartbeat updating
	end
end

lightPrompt.Triggered:Connect(HandleLight)
HandleLight()
1 Like

CFrame orientation works as Orientation = CFrame * CFrame.Angles(), and I believe it takes Radians, not degrees.

Anyways, glad that worked. I did nothing here anyway LOL

Thats great! Glad is working now!
Would be asking too much, if you give me the solution cause I solved the issue? xD :sweat_smile:

Por cierto! Holaaa de nuevooo!!! :yum:

Sure! Copy and paste the script I made the solution because I want to make sure if anyone else has this problem they can use a script based of the one we made.

Ohhh, got it, well the script we were working on:

local RunService = game:GetService("RunService")

local Light = workspace.Office.Light.Bulb:WaitForChild("SpotLight")
local Sound = workspace.Office.Light:WaitForChild("FlickeringLightSound")

local Switch = workspace.Office.Lightswitch:WaitForChild("Switch")

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

local HeartBeatConn

local lightStatus = false

local OriginalLightAngle = 180
local OriginalTrasparency = 0

local function HandleLight()
	if not lightStatus then
		lightStatus = true

		Sound:Play()
		Light.Parent.Material = Enum.Material.Neon
		Light.Enabled = true
		
		Switch.Orientation = Vector3.new(35, 0, 0)

		HeartBeatConn = RunService.Heartbeat:Connect(function()
			Light.Angle = OriginalLightAngle - (Sound.PlaybackLoudness * 0.5)
			Light.Parent.Transparency = OriginalTrasparency + (Sound.PlaybackLoudness/10)
		end)
	else
		lightStatus = false

		Light.Parent.Material = Enum.Material.Plastic
		Light.Enabled = false
		Sound:Stop()
		
		Switch.Orientation = Vector3.new(55, 180, 180)

		HeartBeatConn:Disconnect() -- stop the heartbeat updating
	end
end

lightPrompt.Triggered:Connect(HandleLight)
HandleLight()
2 Likes

Good job @Dev_Peashie, I was stuck on that for so long.

1 Like

No problem, it was fun working on this together :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.