Hi I am trying to make an scp-3008 game but I ran to this problem.
The sound of the day won’t stop playing when its night. Help pls?
local DayDuration = 30 --360
local NightDuration = 20 --240
local Day = game.ReplicatedStorage.Day
local music
function ConvertToMin(seconds)
return seconds / 60
end
local IsDay = false
local count = 1
local AllDays = {"Monday","Tuesday","Webnesday","Thursday","Friday","Saturday","Sunday"}
function CheckDay()
if IsDay == true then
print("IsDay")
return true
end
print("IsNight")
return false
end
function LoopDay()
while wait() do
IsDay = true
music = game.ReplicatedStorage.WeekMusics:FindFirstChild(AllDays[count])
if CheckDay() == true then
music.Playing = true
end
print("Day!")
game.Lighting.ClockTime = 14.5
for i=DayDuration,0,-1 do
if i < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = i
wait(1)
end
print("Night!")
IsDay = false
if CheckDay() == false then
repeat music:Stop() until music.Playing == false
end
game.Lighting.ClockTime = 0
for y=NightDuration,0,-1 do
if y < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = y
wait(1)
end
print("Passed A Day.")
count += 1
if count > 7 then
count = 1
end
Day.Value += 1
end
end
LoopDay()
I will try to run in Studio my own and check, the CheckDay() function is pointless cause it is function doing
if (condition) then
return true else return false
… you can just say if (condition) in the main code without the need to make this extra function. Imagine if every single condition needs a function, it would be a mess.
Everything works in Studio for me, it stops at night and another day’s music starts on the next day…So problem is not in the code, probably problem in sound properties or maybe pc/studio needs a restart
I see in the script where you set music.playing to true but i dont see where you are then setting it back to false, only place you mention music.playing to false is
But you aren’t setting it to false you are just saying repeat until it is false. You need to set music.playing to false somewhere with a music.playing = false, not music.playing == false.
A workaround as @Aced_Machine mentioned is to use music:Play() instead of music.playing = true. That way the sound isnt left playing.
local DayDuration = 30 --360
local NightDuration = 20 --240
local Day = game.ReplicatedStorage.Day
local music
function ConvertToMin(seconds)
return seconds / 60
end
local IsDay = false
local count = 1
local AllDays = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}
function LoopDay()
while wait() do
IsDay = true
music = game.ReplicatedStorage.WeekMusics:FindFirstChild(AllDays[count])
if IsDay == true then
music:Play()
end
print("Day!")
game.Lighting.ClockTime = 14.5
for i=DayDuration,0,-1 do
if i < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = i
wait(1)
end
print("Night!")
IsDay = false
if IsDay == false then
music:Stop()
end
game.Lighting.ClockTime = 0
for y=NightDuration,0,-1 do
if y < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = y
wait(1)
end
print("Passed A Day.")
count += 1
if count > 7 then
count = 1
end
Day.Value += 1
end
end
LoopDay()
local DayDuration = 30 --360
local NightDuration = 20 --240
local Day = game.ReplicatedStorage.Day
local music = game.ReplicatedStorage.WeekMusics:FindFirstChild(AllDays[count])
function ConvertToMin(seconds)
return seconds / 60
end
local IsDay = false
local count = 1
local AllDays = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}
function LoopDay()
while wait() do
IsDay = true
if IsDay == true then
music:Play()
end
print("Day!")
game.Lighting.ClockTime = 14.5
for i=DayDuration,0,-1 do
if i < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = i
wait(1)
end
print("Night!")
IsDay = false
if IsDay == false then
music:Stop()
end
game.Lighting.ClockTime = 0
for y=NightDuration,0,-1 do
if y < 1 then
break
end
game.ReplicatedStorage.Remaining.Value = y
wait(1)
end
print("Passed A Day.")
count += 1
if count > 7 then
count = 1
end
Day.Value += 1
end
end
LoopDay()