Sound won't stop playing?

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()
1 Like

Check Sound properties.


If Looped is true, It probably won’t stop

image
It isnt looped.

Not so sure if that will fix it but don’t use music.Playing=true, use music:Play() instead

Also what is the point of this CheckDay() function… >_>

Hi! I tried but it wont stop either. The Checkday() is like when you know its day or night

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

Oh ok. I might try restarting my pc

If that didn’t solve it maybe double check sound properties maybe the id for both monday and tuesday is the same ?!

It still doesn’t work? It’s still playing.

image
image

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.

I tried. This is the recent code

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()

Try defining this up top instead.

Then reference it where you have it now.

Can you show me? idk what to do.

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()

Still doesn’t work for me. I restarted the studio and pc many times

Have you tried publishing the update and playing it on the ROBLOX Client? Perhaps this is just a ROBLOX Studio issue on your end.

Ok, I’ll try playing on roblox.

Does the ouput show any errors, and also does it print “Night!”?