Music mute button acting weird

i making guess the anime game and i have music system. my mute button act weird when i change the volume of the sound the mute button doesnt work. i dont know why please help me.

mute script(local script):

local RP = game:GetService("ReplicatedStorage")

local music = RP:WaitForChild("CurrentMusic")


script.Parent.MouseButton1Click:Connect(function()

if music.Volume == 0.5 then

 music.Volume = 0

 else

  music.Volume = 0.5

end
end)

music system model: Music System - Roblox

I couldn’t hear anything in the video you attached, but I think the issue is that the music keeps playing when you set the volume to 0. If you want the music to pause, you can use the Sound:Pause() function to pause the music.

Does the audio actually play, if not then you need to move it to a different location, instead of ReplicatedStorage.

yes the audio play always but when i change the volume to something else then 0.5 the mute button not working.

Have you tried using a Boolean instead of music.Volume. So your code would look like

mute = not mute
music.Volume = (mute and 0) or 0.5

im new to script i dont know what to do with what you write me

You can use music:Stop and music:Play() instead of music.Volume

Also why is there 2 of this post?

As I said in the last Topic post.

When you change the values in the if statement. You Ignore the fact volume is set to 0.5 by your music system If your going to change the values within the if statement. You need to set the values so that your if statements’ conditions can be true.

I think that sounds don’t update as soon as the value is changed, they change when they play again, for example, if you change the volume, the music has to play again/restart/pause then unpause to change

Not sure what you mean

Your solution would be

if music.IsPlaying then
music:Stop()
else
music:Play()
end

I just what him to understand that music is set to 0.5. He alters his scripts condition to say

if music.Volume == 0.2 then -- But with volume being 0.5 it will NOT run
 music.Volume = 0
 else
  music.Volume = 0.2
end

I just want him to understand what’s wrong really I wasn’t trying to solve and provide a better solution.

your script not working its stop the music but when i press again its doesnt play

this is the problem:

local RP = game:GetService("ReplicatedStorage")
local music = RP:WaitForChild("CurrentMusic")

local isMuted = false
script.Parent.MouseButton1Click:Connect(function()
 isMuted = not isMuted
if isMuted then
 music.Volume = 0
else
  music.Volume = 0.5
end
end)

This should work.

This is the solution

I kept trying to explain to you that changing the if statements volume was wrong because the music volume is 0.5 In-game
i literally wrote

if music.Volume == 0.2 then -- But with volume being 0.5 it will NOT run

Dude Thanks you so much i love you

1 Like

the script that you send me is not working

Which script i made quite alot. I dont know which one your refering to