Mute button doesnt work promptly

I making guess the anime game and i have music system. my mute button doesnt work when song is switched pls help me i dont know what to do.

mute button 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)

please check the music system model: Music System - Roblox

Im newer to scripting, but wouldn’t this make it so they would have to click twice if the song isn’t at the perfect volume? I feel that using a script to permanently set each musics volume would be more efficient

Is your script in a LocalScript?

yea its is a local script why?

I wasn’t sure if your script was in a LocalScript or not.

Anyway, are there any errors in the output? (I am asking this because I tested the model you provided with the script you also provided and they worked completely fine.)

i know its work fine but when a song is switched to the next song the mute button doesnt work

Oh I misread your post.

The issue was with the script that sets the music. It never sets the new song after it finishes.

I was having issues with the audios loading when in ReplicatedStorage. I recommend moving the audio into workspace.
also set the property looped to false on the sound.

Try this, in the server script. not the localscript.

local currentSound = workspace:WaitForChild("CurrentMusic")

local songs = {
	-- your audio ids here seperated by a comma.
}

while true do
	for i, song in pairs(songs) do
		currentSound.SoundId = "rbxassetid://" .. song
		
		if (not currentSound.IsLoaded) then
			currentSound.Loaded:Wait()
		end
		
		currentSound:Play()
		currentSound.Ended:Wait()
	end
end

Let me know if this worked!

1 Like

no dude its not working.

i need to put the audio like that?
image

This will work, its short and precise. Be sure that the music is playing.

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

script.Parent.MouseButton1Click:Connect(function()
    local volumeToSet = music.Volume == .5 and 0 or .5
    music.Volume = volumeToSet
end)

Misinterpreted OP

dude its works thank you very much,

1 Like