I have script for a 60 minute day cycle, which means its day for 30 minutes and night for 30 minutes. I am new to scripting and I attempted to create a script that will loop music during the day, and a different music at night.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() repeat wait() until player.Character if game.Lighting.ClockTime > 5 and game.Lighting.ClockTime < 17 then script.Day:Play() script.Night:Stop() if game.Lighting.ClockTime > 17 and game.Lighting.ClockTime < 5 then script.Night:Play() script.Day:Stop() end end end) end)
The layout is as follows:
LocalScript Day Sound Night Sound
This script isn't working and plays nothing at all. Advice? Please be descriptive!
You need to use a while loop to constantly check if it is day/night. If you don't, the game will just check once and never check afterwards.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() repeat wait() until player.Character while wait() do if game.Lighting.ClockTime > 5 and game.Lighting.ClockTime < 17 then script.Day:Play() script.Night:Stop() if game.Lighting.ClockTime > 17 and game.Lighting.ClockTime < 5 then script.Night:Play() script.Day:Stop() end end end end) end)