I can't stop the music

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make the radio music stop as soon as the radio was turned off

  2. What is the issue? I can’t stop the music, and the “Started” boolValue doesn’t change despite the script being able to go through it.

  3. What solutions have you tried so far? I have tried putting the sound into Debris Service, tried using :Stop(), .Playing = false, :Destroy(), :Remove(), etc.

local Title = script.Parent.SurfaceGui.Title
local Radio = script.Parent
local Prompt = Radio.ProximityPrompt
local Started = Radio.Parent.Started.Value
local MusicFolder = Radio.Parent.MusicFolder:GetChildren()
local Musics = Radio.Parent.MusicFolder

local Debris = game:GetService("Debris")

Prompt.Triggered:Connect(function()
	local Music = MusicFolder[math.random(1, #MusicFolder)]:Clone()
	
	if Started == false then
		Started = true
		Prompt.ActionText = "Turn off"
		Radio.Start:Play()
		Radio.Static:Play()
		Title.Text = "..."
		wait(1)
		Music.Parent = Radio
		Music:Play()
		Title.Text = Music.Name
	else
		Started = false
		Prompt.ActionText = "Turn on"
		Title.Text = " "
		Radio.Start:Play()
		Radio.Static:Stop()
		Music:Destroy()
		print("Stopped")
	end
end)

The code above is the one that I used, it’s in a server script, located inside the radio part.

image

The musics are not looped, the static sound is the only one that’s looped.

The script did go through the print(“stopped”) part.

There are also no errors in the output tab.

you have to set the variable Started to the instance, not the value

Change line 4 to:
local Started = Radio.Parent.Started

and use Started.Value = true to set the value to true

When you set local Started = Radio.Parent.Started.Value, the variable just takes the value of ‘Started’, in this case, it would be a normal boolean variable (false).

1 Like

I’ve changed it, still didn’t work. The Started value did change tho.

local Title = script.Parent.SurfaceGui.Title
local Radio = script.Parent
local Prompt = Radio.ProximityPrompt
local Started = Radio.Parent.Started
local MusicFolder = Radio.Parent.MusicFolder:GetChildren()
local Musics = Radio.Parent.MusicFolder

local Debris = game:GetService("Debris")

Prompt.Triggered:Connect(function()
	local Music = MusicFolder[math.random(1, #MusicFolder)]:Clone()
	
	if Started.Value == false then
		Started.Value = true
		Prompt.ActionText = "Turn off"
		Radio.Start:Play()
		Radio.Static:Play()
		Title.Text = "..."
		wait(1)
		Music.Parent = Radio
		Music:Play()
		Title.Text = Music.Name
	else
		Started.Value = false
		Prompt.ActionText = "Turn on"
		Title.Text = " "
		Radio.Start:Play()
		Radio.Static:Stop()
		Music:Destroy()
		print("Stopped")
	end
end)

Here’s the new code.

I’ve tried that, still didn’t work, the started value changed but the music didn’t stop

does the music have PlayOnRemove enabled? maybe add Music:Stop()?

2 Likes

PlayOnRemove is disabled, I already tried Music:Stop(), the :Stop() thing works on my “Start” and “Static” sounds but not the musics

I found the solution, I don’t know why it works this time but it did.
Here’s the new code:

local Title = script.Parent.SurfaceGui.Title
local Radio = script.Parent
local Prompt = Radio.ProximityPrompt
local Started = Radio.Parent.Started
local MusicFolder = Radio.Parent.MusicFolder:GetChildren()
local Musics = Radio.Parent.MusicFolder

local Debris = game:GetService("Debris")

local function ChooseMusic(Music)
	if Started.Value == true then
		Radio.Static:Play()
		Music.Parent = Radio
		Title.Text = "..."
		Prompt.ActionText = "Turn off"
		wait(1)
		Music:Play()
		Title.Text = Music.Name
	end
end

local function StopMusic(Music)
	if Started.Value == false then
		Prompt.ActionText = "Turn on"
		Title.Text = " "
		Radio.Static:Stop()
		Music:Destroy()
	end
end

Prompt.Triggered:Connect(function()
	local Music = MusicFolder[math.random(1, #MusicFolder)]:Clone()
	
	Radio.Start:Play()
	
	if Started.Value == false then
		Started.Value = true
		ChooseMusic(Music)
	else
		Started.Value = false
	end
	
	Started.Changed:Connect(function()
		StopMusic(Music)
	end)
	
	Music.Ended:Connect(function()
		ChooseMusic(Music)
	end)
end)

Thanks to those who have helped me with this problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.