How I Make Background Ambience That Sound Changes When On Specfic Time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I Want To Make The Background Ambience Sound That Changes When Time Reaches Specfic Time, Like When It Night, The Sound Changes To Night Ambience Sounds.

  2. What is the issue? I Don’t Really Know How To Make It, So I Decide To Make The Script With Intuition, And Yes, It Didn’t Work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I Looked The DevForum But Not Found Any Topic That Similar To Mine.

local musicbox = game.Workspace.BackgroundSound
local timecycle = game.Lighting.TimeOfDay

if timecycle == "08:00:00" then
	musicbox.Sound.SoundId = "rbxassetid://9118752861"
elseif timecycle == "18:00:00" then
	musicbox.Sound.SoundId = "rbxassetid://9112836038"
end

musicbox.Sound:Play()

Can you try this?

local Lighting = game:GetService("Lighting")
local musicbox = game.Workspace.BackgroundSound

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local ClockTime = Lighting.ClockTime

	if ClockTime >= 18 or ClockTime >= 0 and ClockTime <= 7 then -- if night
		musicbox.Sound.SoundId = "rbxassetid://9112836038"
		musicbox.Sound:Play()
	else -- if not
                musicbox.Sound.SoundId = "rbxassetid://9118752861"
		musicbox.Sound:Play()
	end
end)
1 Like

i tried your script, and it played the sound on night, but somehow ambience not plays on day

1 Like

try this:

local Lighting = game:GetService("Lighting")
local musicbox = game.Workspace.Folder

musicbox.Sound:Play()

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local ClockTime = Lighting.ClockTime

	if ClockTime >= 18 or ClockTime >= 0 and ClockTime <= 7 then -- if night
		musicbox.Sound.SoundId = "rbxassetid://9112836038"
		musicbox.Sound:Play()
	elseif ClockTime < 18 or ClockTime > 7 then -- if not
		musicbox.Sound.SoundId = "rbxassetid://9118752861"
		musicbox.Sound:Play()
	end
end)