Audio is not :Play()ing when called in a function, but :Play()s when outside of it

So this is weird…

I am trying to :Play() an audio in a function (that is called via ProximityPrompt.Triggered) and it does not work. If I do that anywhere else in the Script, it plays as expected.
This is insanely strange, because I have another audio in that exact same function and it plays as expected.

And no, this is not because something is happening with the audio instance itself. As I said, it is playing perfectly fine anywhere else in the code.

Also, when I print out if the not working audio’s IsPlaying, it returns true?

	proximity.Enabled = false
	--blah blah blah
	audio:Play() --doesn't play
	print(audio.IsPlaying) --prints true
	print(audio.IsPlaying) --still returns true

	--hippity hoppity stuff idk

NO, the audio is not short at all (it’s 17 secs) and I am even preloading it.


Print the isPlaying before you actually play the sound, see what prints.

You can also try to disable the proximity after the sound has been instructed to play, it could be because the function stops when it’s actual proximity prompt disables.

1 Like

It prints false as expected.

Didn’t work.

Are you using the same variable names for both audios? That’s the only thing which came into my mind when you mentioned that it plays as expected anywhere in the code. Maybe you are double playing the same audio and then that same audio returns true because it is really playing.

Do you have any other sound which is playing too? Sometimes, some sounds cover some other sound

Sorry for late response.

@Boustifail There is no other audio playing at the moment of me using :Play() on the not working audio.

@Aerodymier No. There is only one variable with the name audio.

Sometimes, it can glitch out. I have the situation where one attack spam thunder bolts which play sounds but the main attack which has one sound doesn’t play. Maybe you can report it as a bug? I am not sure

What is the volume of ur audio?

He mentioned that the sound works on other scripts, it’s not the volume.

Is there anything inside the script that’s changing the audio variable in any way? If so, show me it here.

Try using if not (audio directory).IsPlaying . It worked for me, it triggers whenever the audio isn’t playing,

It strangely prints out true if you check the audio status after firing :Play().

My guess is that this is a Roblox studio bug, since the audio has to play if :Play() is fired, and IsPlaying is being set to true.

1 Like

No, the audio is not being reassigned in any way inside the function.

I am thinking to report this as a bug since there is seemingly no other explanation.

Where is the sound located? Is it located in a place that would allow sound to be played (within a part in the workspace, In the SoundService)? You’ll have to parent the audio to a place capable of producing sound.

I literally said that the sound is playing everywhere outside of the function. This is most likely a bug and I will open a ticket soon.

Oop, my apologies. Alright, I hope it gets sorted. :slight_smile:

The “blah blah blah” code, can you actually show it, even if it’s irrelevant. It might be yielding something.