Radio script - Sound doesn't pause

Hello !

Trying to make a local Radio GUI with preset sounds, currently script is not finished yet the sound starts but I can’t stop/pause the sounds in this state, I am not sure which point is wrong, I have tried several more ways such as using sounds[position]:Play() or Resume() and sounds[position]:Stop() or Pause() as well, the script looks like returning the Print commands I write to the top and bottom of sounds[position]:Stop / :Pause() commands however it does not stop.

Here is the code of the Radio ;

local sound1 = script.sd1
local sound2 = script.sd2
local sound3 = script.sd3
local sound4 = script.sd4
local sound5 = script.sd5
local sound6 = script.sd6
local sound7 = script.sd7
local sound8 = script.sd8
local sound9 = script.sd9
local Menu = script.Parent.Menu
local PlayButton = Menu.Play
local SongLabel = Menu.SongName
local SongVolume = Menu.SongVol
local LastSong = Menu.LastS
local NextSong = Menu.NextS
local LoopToggle = Menu.LoopS
local CurrentSound = false
local currentTime = 60

local sounds = {sound1, sound2, sound3, sound4, sound5, sound6, sound7, sound8}

nsound1 = "Test1"
nsound2 = "Test2"
nsound3 = "Test3"
nsound4 = "Test4"
nsound5 = "Test5"
nsound6 = "Test6"
nsound7 = "Test7"
nsound8 = "Test8"
nsound9 = "Test9"

local toggle = false

local position = 1

local repea = false

	if toggle == false then
		toggle = true
		sounds[position].Playing = true
		while toggle == true do
			repeat wait(1) until currentTime == 0
			print ("Waited")
			position = position + 1
			if position	>= #sounds then
				position = 1
			sounds[position].Playing = true
	elseif toggle == true then
		toggle = false
		sounds[position].Playing = false

	if position == sound1 then
		currentTime = sound1.TimeLength
	elseif position == sound2 then
		currentTime = sound2.TimeLength
	elseif position == sound3 then
		currentTime = sound3.TimeLength
	elseif position == sound4 then
		currentTime = sound4.TimeLength
	elseif position == sound5 then
		currentTime = sound5.TimeLength
	elseif position == sound6 then
		currentTime = sound6.TimeLength
	elseif position == sound7 then
		currentTime = sound7.TimeLength
	elseif position == sound8 then
		currentTime = sound8.TimeLength
	elseif position == sound9 then
		currentTime = sound9.TimeLength
	repeat wait(1 )until currentTime == 0 do
	currentTime = currentTime - 1

	if repea == false then
		repea = true
		sounds[position].Looped = true
	elseif repea == true then
		repea = false
		sounds[position].Looped = false

Any help would be great

It would be easier to help if you posted a file - difficult to work out without GUI or sounds.

I would say that from a quick look this certainly doesn’t look right:


Sound.IsPlaying is not an event, it’s a property?

Instead, just use RenderStepped / Heartbeat for the “IsPlaying” event.

I know that IsPlaying is wrong, it was just something I tried on the way, here is another script that didn’t worked out, as well as some other ways too…

The problem we have is with songs not stopping, if anyone can help with it

Use the Sound.Ended event to wait for a sound to finish, it’s usually better than polling like this.

Its not the problem, we tried it but doesn’t work.

I explain in a different way :slight_smile:

We got a GUI with a play button on it that activates the sound. When you press it again, it should stop at a given time, Pause. The pause event doesn’t work. So the song isn’t stopped and continues playing still after we click

I haven’t actually ran the code but it’s probably a “blocking” issue - looking at your code the click handler looks like it will run for all songs so 8 minutes before any other click will execute PlayButton.MouseButton1Click:Connect

Off the top of my head, you could look at using BindableEvent for the button clicks to control the music