New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Can't make mute music button work, anyone know the problem?

Asked by 3 months ago

I tried making a function that activates on a RemoteEvent being triggered. It's triggered by the player's mute music button. Here's the code in ServerScriptService for when it's triggered:

-- Mutes/unmutes the player's music 
game.ReplicatedStorage.muteMusic.OnServerEvent:Connect(function(player)
    local isMuted = workspace.isMuted.Value 
    local playing = workspace.audio1.Playing
    if isMuted == true then -- Music is muted 
        -- Make music unmuted 
        isMuted = false 
        playing = true 

        -- Just making sure 
        print("Unmuted")
    else -- Music is not muted 
        -- Make music muted 
        isMuted = true 
        playing = false 

        -- Just to make sure it works 
        print("Muted")
    end
end)

It prints "Muted" every time I press it. Please help me if you can. Thx.

2 answers

Log in to vote
1
Answered by
Prestory 1390 Moderation Voter
3 months ago
Edited 3 months ago

Insert a Sound object into StarterGui and call it Music then inside the button you want them to press the (mute/unmute one) create a local script and paste this code inside it.

local Player = game:GetService('Players').LocalPlayer

local PlayerGui = Player:WaitForChild('PlayerGui') 

local Music = PlayerGui:WaitForChild('Music')

local isPlaying = false 

script.Parent.MouseButton1Click:Connect(function() 
    if not isPlaying then
        isPlaying = true
        Music:Resume()
    else 
        Music:Pause()
        isPlaying = false 
    end
end)
Ad
Log in to vote
0
Answered by 3 months ago

This is happening because when you defined local isMuted = workspace.isMuted.Value it will always be the same value, you have to define isMuted like this: local isMuted = workspace.isMuted and replace isMuted on every other bit of the script with isMuted.Value.The finished/fixed script should be:

-- Mutes/unmutes the player's music 
game.ReplicatedStorage.muteMusic.OnServerEvent:Connect(function(player)
    local isMuted = workspace.isMuted
    local playing = workspace.audio1.Playing
    if isMuted.Value == true then -- Music is muted 
        -- Make music unmuted 
        isMuted.Value = false 
        playing = true 

        -- Just making sure 
        print("Unmuted")
    else -- Music is not muted 
        -- Make music muted 
        isMuted.Value = true 
        playing = false 

        -- Just to make sure it works 
        print("Muted")
    end
end)

Answer this question