How can I detect when a sound reaches a certain point in it?

I have this sound and this is my attempt at trying to check and run code;

runService.RenderStepped:Connect(function()
			if game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"].TimePosition == 95 then
				game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"].ReverbSoundEffectEnd.Enabled = true
				spawn(function()
					game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"]:Pause()
					game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"]:Play()
					wait(.25)
					game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"].ReverbSoundEffectEnd.Enabled = false
				end)
				game.SoundService.Temp["Pmac - One (Loneliest Number Rap)"]:Stop()
				game.SoundService.Effects["Boom Sound Effect"]:Play()
				playerGui.EndScreen.Enabled = true
			end
		end)

You already have a if statement at the top checking the time position, is it that the script is not working?

1 Like

No it is not working unfortunately.

1 Like

Could you give a bit more context?
What are you trying to do with this script?

I want to stop the music when It reaches this point in the sound.

You should also check if it’s greater than the specified number. Chances are, RenderStepped is not picking up every single number as it usually fires at 60fps.

Yes I already knew this from the title;

I would read what dukzae said. I do not understand RenderStepped, but sometimes you can’t just always depend on the value to be that when it checks, because it is always changing. Try doing the actions when the value is greater than or equal to 95.

Alright I fixed it just had to do greater than on my if statement.

Why did you mark your own reply as the solution? @dukzae’s reply gave you your solution, that should be the solution.

3 Likes