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)
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
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.)
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
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)