Script works in studio, but not on normal server

local countdown = 5
local night = true
local day = false
while countdown ~= 0 do
	countdown -= 1
	wait(1)
end
if night then
	for i, v in pairs(game.Workspace.Lights:GetChildren()) do

		v.Light.SurfaceLight.Brightness = 0

		v.Light.BrickColor = BrickColor.new(0, 0, 0)

		v.Light.Noise.Volume = 0

		local TurnOff = workspace.TurnOff:Clone()
		TurnOff.Parent = workspace
		TurnOff.Volume = 0.05
		TurnOff:Play()
if day then
	for i, v in pairs(game.Workspace.Lights:GetChildren()) do

		v.Light.SurfaceLight.Brightness = 1

		v.Light.BrickColor = BrickColor.new(Color3.fromRGB(248, 248, 147))

		v.Light.Noise.Volume = 0.1

		local TurnOn = workspace.TurnOn:Clone()
		TurnOn.Parent = workspace
		TurnOn.Volume = 0.05
		TurnOn:Play()
			end
		end
		end
end

pls fix this script omg

What doesn’t work? The lights don’t turn off after 5 seconds?

while i test it in studio, it works perfectly, the lights turn off, but when i try it on NORMAL server ( not studio one ) it doesnt work, it just plays the turn off audio, the lights dont turn off

I tested your script, and it works for me, although there are some bad practices, I can address that with you after I understand what you might be doing wrong.

Do you want the turn on and turn off sound to play for the whole game server, or just at the light part?

Also, what is ‘Noise’ for in the Light part?

Since you dont provide much context as to what the point of this is.

Here is the code made with the following assumptions:

  1. You want the on/off sound to play on the server.
  2. You aren’t sure if every model has a light part and you arent sure if every Light part has a ‘Noise’ SoundObject.
  3. You added a while loop on purpose to run some kind of function every second for the initial 5 second countdown.
local countdown = 5
local night = true
local TurnOff, TurnOn = workspace.TurnOff, workspace.TurnOn
repeat 
	--Function to do every second for some reason?
	wait(1)
	countdown = countdown -1
until countdown <= 0

if night then
	for i, v in pairs(workspace.Lights:GetChildren()) do
		if v:FindFirstChild("Light") and v.Light:FindFirstChild("Noise") then
			v.Light.SurfaceLight.Brightness = 0
			v.Light.Color = Color3.fromRGB(0, 0, 0)
			v.Light.Noise.Volume = 0
		end
	end
	TurnOff.Volume = 0.05
	TurnOff:Play()
elseif night == false then
	for i, v in pairs(workspace.Lights:GetChildren()) do
		if v:FindFirstChild("Light") and v.Light:FindFirstChild("Noise") then
		v.Light.SurfaceLight.Brightness = 1
		v.Light.Color = Color3.fromRGB(248, 248, 147)
		v.Light.Noise.Volume = 0.1
		end
	end
	TurnOn.Volume = 0.05
	TurnOn:Play()
end

If your script has an error, it would be helpful for you to send a screen shot of the developer console before you use this script I sent you.

To view the developer console in game, press f9 and click on the Server tab. (assuming this is a server script.

Notes:

A. Only screenshot the error lines of the developer console. If the console shows sensitive game information do not include it in the screenshot, I understand.

B. If this is not a server script, let me know. That is actually very important.

These conditionals are only being checked when the script first executes, you need to wrap them inside a loop if you need them to be repetitively checked.