Script supposed to work only at night works at all times

So I was trying to design a script for certain text to flash Neon when ClockTime is after/at 18 and before/at 6. But, when I tested it, it works at all times. I’ve tried looking at what I was using at the developer.roblox.com site to make sure it should all work, but it looked like it all should. No problems in the Output either. I’m lost. Here’s the script:

local CasinoText = game.Workspace.CasinoText
local Smooth = Enum.Material.SmoothPlastic
local Neon = Enum.Material.Neon

while true do
if game.Lighting.ClockTime >= 18 or game.Lighting.ClockTime <= 6 then
wait(1)
CasinoText.A2.Material = Neon
CasinoText.A.Material = Neon
CasinoText.C.Material = Neon
CasinoText.E.Material = Neon
CasinoText.G.Material = Neon
CasinoText.I.Material = Neon
CasinoText.L.Material = Neon
CasinoText.N.Material = Neon
CasinoText.N2.Material = Neon
CasinoText.O.Material = Neon
CasinoText.S2.Material = Neon
CasinoText.S.Material = Neon
wait(1)
CasinoText.A2.Material = Smooth
CasinoText.A.Material = Smooth
CasinoText.C.Material = Smooth
CasinoText.E.Material = Smooth
CasinoText.G.Material = Smooth
CasinoText.I.Material = Smooth
CasinoText.L.Material = Smooth
CasinoText.N.Material = Smooth
CasinoText.N2.Material = Smooth
CasinoText.O.Material = Smooth
CasinoText.S2.Material = Smooth
CasinoText.S.Material = Smooth
wait(1)
CasinoText.A.Material = Neon
wait(1)
CasinoText.A.Material = Smooth
CasinoText.N.Material = Neon
wait(1)
CasinoText.N.Material = Smooth
CasinoText.G.Material = Neon
wait(1)
CasinoText.G.Material = Smooth
CasinoText.E.Material = Neon
wait(1)
CasinoText.E.Material = Smooth
CasinoText.L.Material = Neon
wait(1)
CasinoText.L.Material = Smooth
CasinoText.S.Material = Neon
wait(1)
CasinoText.S.Material = Smooth
CasinoText.C.Material = Neon
wait(1)
CasinoText.C.Material = Smooth
CasinoText.A2.Material = Neon
wait(1)
CasinoText.A2.Material = Smooth
CasinoText.S2.Material = Neon
wait(1)
CasinoText.S2.Material = Smooth
CasinoText.I.Material = Neon
wait(1)
CasinoText.I.Material = Smooth
CasinoText.N2.Material = Neon
wait(1)
CasinoText.N2.Material = Smooth
CasinoText.O.Material = Neon
wait(1)
CasinoText.O.Material = Smooth
wait(1)
CasinoText.A2.Material = Neon
CasinoText.A.Material = Neon
CasinoText.C.Material = Neon
CasinoText.E.Material = Neon
CasinoText.G.Material = Neon
CasinoText.I.Material = Neon
CasinoText.L.Material = Neon
CasinoText.N.Material = Neon
CasinoText.N2.Material = Neon
CasinoText.O.Material = Neon
CasinoText.S2.Material = Neon
CasinoText.S.Material = Neon
wait(1)
CasinoText.A2.Material = Smooth
CasinoText.A.Material = Smooth
CasinoText.C.Material = Smooth
CasinoText.E.Material = Smooth
CasinoText.G.Material = Smooth
CasinoText.I.Material = Smooth
CasinoText.L.Material = Smooth
CasinoText.N.Material = Smooth
CasinoText.N2.Material = Smooth
CasinoText.O.Material = Smooth
CasinoText.S2.Material = Smooth
CasinoText.S.Material = Smooth
end
end

Here, try this instead:

local CasinoText = game.Workspace.CasinoText
local Smooth = Enum.Material.SmoothPlastic
local Neon = Enum.Material.Neon

while true do
	if game.Lighting.ClockTime < 6 and game.Lighting.ClockTime > 18 then
		task.wait(1)
		for i,v in pairs(CasinoText:GetChildren()) do
			v.Material = Enum.Material.Neon
		end
		task.wait(1)
		for i,v in pairs(CasinoText:GetChildren()) do
			v.Material = Enum.Material.Plastic
		end
	end
end
1 Like

Uh, this wouldn’t work. ClockTime cannot be below 6 and above 18 at the same time. The rest would work as a replacement for some part of the script though.

Nevermind, I had it resolved elsewhere. Thanks though.

local Lighting = game:GetService("Lighting")

local CasinoText = workspace.CasinoText
local Count = 0

while true do
	if Lighting.ClockTime <= 6 or Lighting.ClockTime >= 18 then
		Count += 1
		task.wait(1)
		for _, child in ipairs(CasinoText:GetChildren()) do
			if Count % 2 == 0 then
				child.Material = "Smooth"
			else
				child.Material = "Neon"
			end
		end
	end
end

You mentioned this was resolved but I wanted to make it as concise as possible. If it’s happening at all times then you’re not changing the “ClockTime” property (at least not on the server anyway).