Help with deleting a music

Hello there.

So I was making some music in the main menu thing and when you press play the music is supposed to be disabled so you will not hear it again but when I reset my character the music plays even though im not in menu and I disabled it with a script

I tried deleting the sound which did not work at all and I hope someone can help me out

1 Like

Where is the script? Is it in PlayerGui or PlayerScripts?

1 Like

When the character respawns, all of the gui resets, this means the script plays the music again, and it stops working because the main menu doesn’t exist anymore. Put the script in StarterPlayerScripts to solve the issue.

I mean cant i just do a if character dies then make it mute the music again

Yes, you can bind Player.CharacterLoaded to mute the music.

…why not just call Stop on the sound object? Knowing your implementation (code and screenshots of your object hierarchy) would be very valuable here.

1 Like

Instead of doing that, put the music outside of the GUI, perhaps in ReplicatedStorage.

In your script:

if not game.Workspace.CurrentCamera:FindFirstChild( 'Music' ) then
    local music = game.ReplicatedStorage.Music:Clone()
    music.Parent = game.Workspace.CurrentCamera
    music:Play()
end

And then later on when you want to stop it…

-- inside your click handler:
local music = game.Workspace.CurrentCamera:FindFirstChild( 'Music' )
if music then
    music:Stop()
end

The music in your camera shouldn’t be reset when you die, therefore it doesn’t play again as the script can see you’ve already got a music in there.

1 Like