Sound won't play

Hello, @F0xBirdman Unfortunately, you might have to put the sound in a part

Try putting the sound in the part and try again.

2 Likes

Your sound isn’t playing because the if condition isn’t passing. It’s good to debug your own code, such as using prints, to check why something might be occurring. For example, before your if statement, you can check if the operands you’re using are actually equal to each other:

print(game:GetService("Lighting"):GetMinutesAfterMidnight() == (3*60))

And/or just check the value at all:

print(game:GetService("Lighting"):GetMinutesAfterMidnight())

There’s a chance that you aren’t getting an exact value where minutes after midnight is not 180. In that case you can look at other options, from making your day cycle script more predictable with the values its setting to changing when the sound should be played. A lazy example is to use ClockTime instead with a property changed signal, disconnect the connection if the condition is met (ClockTime is above or below a certain value) and then play the sound.

2 Likes

I know the value is correct, I have another script which turns on a light if the clocktime is 3. I think that I am not using the right terms to get a sound to play. (keep in mind that I have the sound in workspace, even in soundservice it won’t play by the script.)

1 Like

It doesn’t hurt to debug. A lot of developers say “I know” but it’s that assumption that leads to an oversight in a problem where what you think you know actually isn’t correct.

Server scripts can’t play sounds in SoundService, only LocalScripts can. That could also be another thing you may want to look into - instead of the server playing the sound, have the client do it. The server has no concept of sound; when it plays a sound, it’s just replicating playback to clients.

3 Likes

did you click “activate” on the sound thingy?

1 Like

I had the same issue and I was able to fix it by adding a task.wait()

1 Like

what i did for this problem is playing the sound through the command line

for me it was:
game:GetService(“ServerScriptService”).VHS.Static.Sound:Play()

so try that then start the game, worked for me.

1 Like

try to use that inside LocalScript.

game.Lighting:GetPropertyChangedSignal('TimeOfDay'):Connect(function()
	if game.Lighting:GetMinutesAfterMidnight() == 3 * 60 then 
		game:GetService("SoundService"):PlayLocalSound(SoundHere)
	end
end)
1 Like