Help with making a script run at a designated time

Hello!
So I’m making a neon sign here, for a bar, and the sign is done, and I need it to ‘turn on’ at 5pm and ‘turn off’ at 2am every night/day.

-- 1 HOUR =     85 seconds
local upri = script.Parent.maple
local pour = script.Parent.pour
local lttr = script.Parent.neonletters
if game.Lighting.TimeOfDay == "18:00:00" then
	lttr.Material = Enum.Material.Neon
	while true do
		wait(1.7)
		upri.Transparency = 0.5
		upri.Material = Enum.Material.Metal
		upri.BrickColor = BrickColor.new("Dark red") 
		pour.Transparency = 0
		pour.Material = Enum.Material.Neon
		pour.BrickColor = BrickColor.new("Bright red") 
		wait(1.7)
		pour.Transparency = 0.5
		pour.Material = Enum.Material.Metal
		pour.BrickColor = BrickColor.new("Dark red") 
		upri.Transparency = 0
		upri.Material = Enum.Material.Neon
		upri.BrickColor = BrickColor.new("Bright red") 
	end

end
if game.Lighting.TimeOfDay == "02:00:00" then
	lttr.Material = Enum.Material.Metal
	lttr.Transparency = 0.5
	lttr.BrickColor = BrickColor.new("Dark red")
	upri.Transparency = 0.5
	upri.Material = Enum.Material.Metal
	upri.BrickColor = BrickColor.new("Dark red") 
	pour.Transparency = 0.5
	pour.Material = Enum.Material.Metal
	pour.BrickColor = BrickColor.new("Dark red") 
end

It seems to be not working, and I would appreciate some help. Thanks!

what’s in the while loop works fine and here’s what it looks like running. (I dont know what my screen recorder did to the framing…)

1 Like

hmm you could put the loop in a corountine and resume it at 5pm and yield it on
2am. coroutine | Roblox Creator Documentation also really respect the name @kitkatsncoffee

@Katrist ik im too used to using them all the time

2 Likes

You shouldn’t use coroutines for this simple of a task. Just use normal events and you should be fine:

--[[
1 HOUR =  85 seconds
]]

--//Services
local Lighting = game:GetService("Lighting")

--//Variables
local upri = script.Parent.maple
local pour = script.Parent.pour
local lttr = script.Parent.neonletters

--//Controls
local isAfternoon = false

--//Functions
Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	if Lighting.TimeOfDay == "18:00:00" then
		isAfternoon = true
		lttr.Material = Enum.Material.Neon

		while isAfternoon do
			task.wait(1.7)
			upri.Transparency = 0.5
			upri.Material = Enum.Material.Metal
			upri.BrickColor = BrickColor.new("Dark red") 
			
			pour.Transparency = 0
			pour.Material = Enum.Material.Neon
			pour.BrickColor = BrickColor.new("Bright red") 
			
			task.wait(1.7)
			pour.Transparency = 0.5
			pour.Material = Enum.Material.Metal
			pour.BrickColor = BrickColor.new("Dark red") 
			
			upri.Transparency = 0
			upri.Material = Enum.Material.Neon
			upri.BrickColor = BrickColor.new("Bright red") 
		end
	end

	if Lighting.TimeOfDay == "02:00:00" then
		isAfternoon = false
		
		lttr.Material = Enum.Material.Metal
		lttr.Transparency = 0.5
		lttr.BrickColor = BrickColor.new("Dark red")
		
		upri.Transparency = 0.5
		upri.Material = Enum.Material.Metal
		upri.BrickColor = BrickColor.new("Dark red") 
		
		pour.Transparency = 0.5
		pour.Material = Enum.Material.Metal
		pour.BrickColor = BrickColor.new("Dark red") 
	end
end)
2 Likes