Hello everyone. Im having trouble getting my code to work. I am trying to make the crickets sound play at night and the morning sounds play in the morning but when I join the game the crickets are automatically playing and don’t stop ever also when it reaches the specified morning time the morning sounds don’t start all I hear is the crickets.
here is my code:
local cricketsSound = workspace.Crickets
local morningSound = workspace.MorningSounds
local cricketsPlaying = false
local morningPlaying = false
local cricketsStartHour = 20 -- start hour for crickets
local cricketsEndHour = 5 -- end hour for crickets (next day)
local morningStartHour = 5 -- start hour for morning sounds
local morningEndHour = 8 -- end hour for morning sounds
while true do
local time = os.date("*t", os.time())
if time.hour >= cricketsStartHour or time.hour < cricketsEndHour then
if not cricketsPlaying then
cricketsSound:Play()
morningSound:Stop()
cricketsPlaying = true
morningPlaying = false
end
elseif time.hour >= morningStartHour and time.hour < morningEndHour then
if not morningPlaying then
morningSound:Play()
cricketsSound:Stop()
morningPlaying = true
cricketsPlaying = false
end
else
cricketsSound:Stop()
morningSound:Stop()
cricketsPlaying = false
morningPlaying = false
end
wait(60) -- wait for 1 minute before checking again
end
Can anyone help with this?