Help with muting music

I’m trying to make script where when uou press the target button,the music mutes.
So my script will be posted down below

local music = game.ReplicatedStorage.CurrentMusic

db = true

script.Parent.MouseButton1Click:Connect(function())

if db == true and music then

db = false

script.Parent.Text = ("Unmute Music")

music.Volume = 0

else

db = true

script.Parent.Text = ("Mute Music")

music.Volume = 0.5

end

end)

I don’t know what’s wrong,no error shown

Try removing the brackets from the script.Parent.Texts.
Also, change this:

script.Parent.MouseButton1Click:Connect(function()) -- Extra Bracket
-- Code

To this:

script.Parent.MouseButton1Click:Connect(function()
-- Code
 

I think the event wasn’t running because the code inside the event was never registered, due to the extra bracket.

EDIT: Sorry, don’t change the ends. Just remove the bracket at the start of the MouseButton1Down connection.

Move current music from ReplicatedStorage to workspace because sounds may not work there

local music = game:GetService("Workspace"):WaitForChild("CurrentMusic")

db = true

script.Parent.MouseButton1Click:Connect(function()

if db == true then

db = false

script.Parent.Text = ("Unmute Music")

music.Volume = 0

else

db = true

script.Parent.Text = ("Mute Music")

music.Volume = 0.5

end

end)

What does this mean?

Infinite yield possible on 'Workspace:WaitForChild("CurrentMusic")'

Move the CurrentMusic to Workspace and i tried playing audio inside ReplicatedStorage and i assume it won’t play

Are you able to hear the music anywhere or it’s parented to a part?

This means that Roblox cannot find the music in workspace. Move the sound to workspace

I never put audio tracks inside of ReplicatedStorage because you won’t going to hear it, i assume

But it works,and this leads to a whole new script for randomising the music

But it does work,and that is another script to randomise the music

Sorry, what? I thought you had an Infinite Yield error.

I mean it DOES play music for my game,you guys were saying that it won’t play for the game

I don’t think I said that, but alright. So are your problems fixed or do you need more assistance?

Yes it plays audio, any updates?

It plays, but does the music mute?

Try my changes and see if that works in muting the music (listed above)

Problems still here,
The infinite yield error

Did you put the sound you want to play in Workspace?

It doesn’t mute the audio still

No it doesn’t,it’s still broken