Music not stopping

hey guys, anyone know why the sound wont stop playing after I go to the next screen? seems pretty straight forward but I don’t know why its not working.

-- Screens

local create = script.Parent.Create

local choice = script.Parent.Parent.ChoiceFrame

--fade variables

local frame = script.Parent

local Ptext = script.Parent.Ptext

local Rtext = script.Parent.Rtext

local Otext = script.Parent.Otext

local Jtext = script.Parent.Jtext

local Etext = script.Parent.Etext

local Ctext = script.Parent.Ctext

local Ttext = script.Parent.Ttext

local Sanctum = script.Parent.TextLabel

--sounds

local sound1 = Instance.new("Sound")

-----------------------------------------------------------------

-- music play

sound1.Volume = .2

sound1.SoundId = "rbxassetid://3163730521"

sound1.Parent = script.Parent.Parent

sound1:Play()

-- animation for title text

Ptext.Visible = true

Ptext:TweenPosition(UDim2.new(0.215,0,-0.0009,75),"Out","Quad", 2, false, nil)

wait(0.5)

Rtext.Visible = true

Rtext:TweenPosition(UDim2.new(0.28,0, 0.0008,75),"Out","Quad", 2, false, nil)

wait(0.5)

Otext.Visible = true

Otext:TweenPosition(UDim2.new(0.364,0, 0.0006,75),"Out","Quad", 2, false, nil)

wait(0.5)

Jtext.Visible = true

Jtext:TweenPosition(UDim2.new(0.449,0, 0.012,75),"Out","Quad", 2, false, nil)

wait(0.5)

Etext.Visible = true

Etext:TweenPosition(UDim2.new(0.519,0, 0.012,75),"Out","Quad", 2, false, nil)

wait(0.5)

Ctext.Visible = true

Ctext:TweenPosition(UDim2.new(0.609,0, 0.005,75),"Out","Quad", 2, false, nil)

wait(0.5)

Ttext.Visible = true

Ttext:TweenPosition(UDim2.new(0.702,0,-0.015,75),"Out","Quad", 2, false, nil)

wait(1.5)

Sanctum.Visible = true

Sanctum:TweenPosition(UDim2.new(0.414,0,0.368,5),"Out","Quad", 2, false, nil)

wait(1.5)

create.Visible = true

create:TweenPosition(UDim2.new(0.494,0,0.754,-3),"In","Quad", 0, false, nil)

-- new game button click

create.MouseButton1Click:Connect(function()

local sound = Instance.new("Sound")

sound.Volume = 1

sound.SoundId = "rbxassetid://2193279623"

sound.Parent = script.Parent

sound:Play()

for i = 0, 1, 0.2 do

create.TextTransparency = i

Ptext.ImageTransparency = i

Rtext.ImageTransparency = i

Otext.ImageTransparency = i

Jtext.ImageTransparency = i

Etext.ImageTransparency = i

Ctext.ImageTransparency = i

Ttext.ImageTransparency = i

Sanctum.TextTransparency = i

wait(1)

end

create.Visible = false

choice.Visible = true

sound1:Stop()

script.FirstScreenFinished:Fire()

end)

1 Like

‘sound1’ gets stopped, but not ‘sound’ ?

sound1 is specifically the the music playing in the background and sound is the just select button sound. Do I have to stop both at the same time?

1 Like

No, but one thing I would do differently is create the click sound before the click function instead of when it’s fired. Do you have any errors?

1 Like

no errors and it plays fine. It’s weird that sound:Play() works but not sound1:Stop()

Can you add a print after this section:

create.Visible = false

choice.Visible = true

To see if it gets to sound1:Stop() ?
and then let us know if you see what you told it to print in console (F9).

-- Screens
local create = script.Parent.Create
local choice = script.Parent.Parent.ChoiceFrame

--fade variables
local frame = script.Parent
local Ptext = script.Parent.Ptext
local Rtext = script.Parent.Rtext
local Otext = script.Parent.Otext
local Jtext = script.Parent.Jtext
local Etext = script.Parent.Etext
local Ctext = script.Parent.Ctext
local Ttext = script.Parent.Ttext
local Sanctum = script.Parent.TextLabel

--sounds
local sound1 = Instance.new("Sound")

-----------------------------------------------------------------

-- music play
sound1.Volume = .2
sound1.SoundId = "rbxassetid://3163730521"
sound1.Parent = script.Parent.Parent
sound1:Play()

-- animation for title text

Ptext.Visible = true
Ptext:TweenPosition(UDim2.new(0.215,0,-0.0009,75),"Out","Quad", 2, false, nil)
wait(0.5)

Rtext.Visible = true
Rtext:TweenPosition(UDim2.new(0.28,0, 0.0008,75),"Out","Quad", 2, false, nil)
wait(0.5)

Otext.Visible = true
Otext:TweenPosition(UDim2.new(0.364,0, 0.0006,75),"Out","Quad", 2, false, nil)
wait(0.5)

Jtext.Visible = true
Jtext:TweenPosition(UDim2.new(0.449,0, 0.012,75),"Out","Quad", 2, false, nil)
wait(0.5)

Etext.Visible = true
Etext:TweenPosition(UDim2.new(0.519,0, 0.012,75),"Out","Quad", 2, false, nil)
wait(0.5)

Ctext.Visible = true
Ctext:TweenPosition(UDim2.new(0.609,0, 0.005,75),"Out","Quad", 2, false, nil)
wait(0.5)

Ttext.Visible = true
Ttext:TweenPosition(UDim2.new(0.702,0,-0.015,75),"Out","Quad", 2, false, nil)
wait(1.5)

Sanctum.Visible = true
Sanctum:TweenPosition(UDim2.new(0.414,0,0.368,5),"Out","Quad", 2, false, nil)
wait(1.5)

create.Visible = true
create:TweenPosition(UDim2.new(0.494,0,0.754,-3),"In","Quad", 0, false, nil)

-- new game button click
create.MouseButton1Click:Connect(function()
    local sound = Instance.new("Sound")
    sound.Volume = 1
    sound.SoundId = "rbxassetid://2193279623"
    sound.Parent = script.Parent
    sound:Play()

    for i = 0, 1, 0.2 do
        create.TextTransparency = i
        Ptext.ImageTransparency = i
        Rtext.ImageTransparency = i
        Otext.ImageTransparency = i
        Jtext.ImageTransparency = i
        Etext.ImageTransparency = i
        Ctext.ImageTransparency = i
        Ttext.ImageTransparency = i
        Sanctum.TextTransparency = i
        wait(1)
    end

    create.Visible = false
    choice.Visible = true
    sound1:Stop()

    script.FirstScreenFinished:Fire()
end)

I only rewrote the code for readability. Functionality remained unchanged.

This code is a nightmare.

1 Like

So it seems to just skip over sound1:Stop() and not even print anything, and the breakpoint stops at sound1:Stop(). There aren’t any red errors that I see in the output. Also yes I know that there are most likely better was to do this. This is just the way I know how for now.

1 Like

Alright, could to try and move sound1:Stop() to before

    create.Visible = false
    choice.Visible = true

and see if that makes any difference?

Yeah still the same thing.

create.MouseButton1Click:Connect(function()
    local sound = Instance.new("Sound")
	sound.Volume = 1
     sound.SoundId = "rbxassetid://2193279623"
	sound.Parent = script.Parent
	sound:Play()
	
	for i = 0, 1, 0.7 do
		create.TextTransparency = i
		Ptext.ImageTransparency = i
		Rtext.ImageTransparency = i
		Otext.ImageTransparency = i
		Jtext.ImageTransparency = i
		Etext.ImageTransparency = i
		Ctext.ImageTransparency = i
		Ttext.ImageTransparency = i
		Sanctum.TextTransparency = i
		wait(1)
		
	end
	
	sound1:Stop()
	create.Visible = false
	choice.Visible = true
	
	print(sound1:Stop())
	
	script.FirstScreenFinished:Fire()
    
	
end)
1 Like

I don’t think the print would print out anything without text input: for example, print("Hi at line#") .
Try changing the print to what I have above and see if you can see that in console when you click the main menu button that you showed us in the video.

Edit: If you still don’t see the print you could also try moving the sound1:Stop() to before the for loop that you have and see if that makes a difference, if it doesn’t something may be playing the same sound.

I assume that sound1 isn’t needed anymore after the first screen finishes, so why not just put it into debris and destroying it?

It is difficult to control the timing of stopping because the music was intended to play until the player hits create.

@roseblade578 Also, why don’t you try to destroy the sound instance, if the intro was intended to play once only?

Just add a sound1.Volume = 0 under a function create.MouseButton1Click once they click on create spirit song volume will change to 0 and song will automatically stop after whole song is played in background silent.

This will produce unnecessary StreamingSound RAM usage.

It still won’t be as high as RAM usage.

It’s always a good practice to destroy unneeded instances. It prolongs a server’s lifetime.

Oh guys i think i get it. So I think what might be happening is that the sound still play because create.visible is just false and its is not complete gone. So I would have to destroy the screen after the next screen becomes visible?