I'm trying to figure out how I can play certain audio's depending on the time of day

This is the current script I’ve got going:

if game.Lighting.ClockTime == “6” then

game.SoundService.Birds:Play()

end

if game.Lighting.ClockTime == “19” then

game.SoundService.Night:Play()

end

Night & Birds are the different audios I have placed into SoundService, I’m most definitely not an individual who scripts very often, if I do, I script very little.

The first issue you’ll find is that ClockTime is a float not a string (get rid of the quotation marks). You also need to encapsulate the functions either in an event or a loop of some sort (RunService or while) so that the if statements don’t run only once.

I appreciate your response, I removed the quotation marks, are you able to give me an example of how I could encapsulate the functions in an event or loop?

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    -- Your code
end)

This will make your code trigger every time the ClockTime property is changed.

2 Likes

I suggest putting the audios in Baseplate as it needs a reference to play the audio from. I think that, along with connecting it to an event as aforementioned by @StaySpy should help you.

Thank you very much for your response.

I greatly appreciate it as well.

Ah, still encountering some issues, not sure what they are, are you able to give me the full script in which I can just edit the id’s and the clocktime?

local Lighting = game.Lighting

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if Lighting.ClockTime == 6 then
		print('Its 6 am! Good morning!')
		game.SoundService.Birds:Play()
	elseif Lighting.ClockTime == 19 then
		print('Its Night! Good night.')
		game.SoundService.Night:Play()
	end

end)
2 Likes