Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this Day - Night cycle not working?

So I want it to where if it's a certain part of the day, it will play a certain song. For some reason this isn't working. Does anyone see anything wrong with the script? Nothing errors, just nothing happens.

This is a LocalScript, and is located in StarterGui.

while true do
wait(1)
if game.Lighting.TimeOfDay > ("6:00:00") and game.Lighting.TimeOfDay < ("12:00:00") then
script.Parent.Midnight2:Stop()
script.Parent.Daytime1:Play()
end
if game.Lighting.TimeOfDay > ("12:00:00") and game.Lighting.TimeOfDay < ("18:00:00") then
script.Parent.Daytime1:Stop()
script.Parent.Daytime2:Play()
end
if game.Lighting.TimeOfDay > ("18:00:00") and game.Lighting.TimeOfDay < ("24:00:00") then
script.Parent.Daytime2:Stop()
script.Parent.Midnight1:Play()
end
if game.Lighting.TimeOfDay > ("24:00:00") and game.Lighting.TimeOfDay < ("6:00:00") then
script.Parent.Midnight1:Stop()
script.Parent.Midnight2:Play()
end
end

1 answer

Your problem is you act like TimeOfDay is a string when it's really a number

This should work

while wait(1) do
	if game.Lighting.TimeOfDay > 6 and game.Lighting.TimeOfDay < 12 then
		script.Parent.Midnight2:Stop()
		script.Parent.Daytime1:Play()
	elseif game.Lighting.TimeOfDay > 12 and game.Lighting.TimeOfDay < 18 then
		script.Parent.Daytime1:Stop()
		script.Parent.Daytime2:Play()	
	elseif game.Lighting.TimeOfDay > 18 and game.Lighting.TimeOfDay < 24 then
		script.Parent.Daytime2:Stop()
		script.Parent.Midnight1:Play()
	elseif game.Lighting.TimeOfDay > 24 and game.Lighting.TimeOfDay < 6 then
		script.Parent.Midnight1:Stop()
		script.Parent.Midnight2:Play()	
	end
end

3 comments

0

TimeOfDay is a string... This does work but your logic is wrong.

0

This didn't work, like Thundermaker300 said TimeOfDay is a string.

0

If TimeOfDay is a string, couldn't you replace the > and < symbols with "==" and change the times so the music doesn't overlap?

This discussion is preserved as it was. New answers, comments, and votes are closed.