Okay, So I have this problem with one of my code (It works properly but doesn’t do how i wanted it to do)
So there’s this Ambience button that mutes the the sound but once you click “resume” and click “menu” and try to unmute it again you’ll have to double click which is annoying!
Menu
--//MENU//
MenuButton.MouseButton1Up:Connect(function()
game.SoundService.Click:Play()
game.SoundService.MenuMusic.Playing = true
if MenuFrame.Position == UDim2.new(-0.5, 0, -0.1, 0) then
Controls:Disable()
MenuFrame:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.25)
MenuButton.Visible = false
-- Increase Blur Size
if Blur.Size <= 0 then
repeat
Blur.Size = math.min(Blur.Size + 5, 20)
wait(0.125)
until Blur.Size == 20
end
-- Adjust Ambience Volume
if game.SoundService.Ambience.Volume <= 1 then
repeat
game.SoundService.Ambience.Volume = math.max(game.SoundService.Ambience.Volume - 0.5, 0.5)
wait(0.125)
until game.SoundService.Ambience.Volume == 0.5
else
game.SoundService.Ambience.Volume = 1
end
else
-- Closing menu animation
MenuFrame:TweenPosition(UDim2.new(-0.5, 0, -0.1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.125)
MenuButton.Visible = true
end
end)
Resume
ResumeButton.MouseButton1Up:Connect(function()
game.SoundService.CloseClick:Play()
if MenuButton.Visible == true and MenuFrame.Position == UDim2.new(-0.5, 0, -0.1, 0) then
-- Closing menu animation
MenuButton.Visible = false
MenuFrame:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.25)
-- Adjusting Ambience volume
if game.SoundService.Ambience.Volume == 0.5 then
repeat
game.SoundService.Ambience.Volume = math.min(game.SoundService.Ambience.Volume + 0.5, 1)
wait(0.125)
until game.SoundService.Ambience.Volume == 1
elseif game.SoundService.Ambience.Volume == 0 then
game.SoundService.Ambience.Volume = 1
repeat
game.SoundService.Ambience.Volume = math.min(game.SoundService.Ambience.Volume + 0.5, 1)
wait(0.125)
until game.SoundService.Ambience.Volume == 1
end
else
Controls:Enable()
game.SoundService.MenuMusic.Playing = false
MenuButton.Visible = true
-- Closing other frames
SettingsFrame:TweenPosition(UDim2.new(1.2, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.25)
UpdatelogFrame:TweenPosition(UDim2.new(1.2, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.25)
ProfileFrame:TweenPosition(UDim2.new(1.2, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.25)
MenuFrame:TweenPosition(UDim2.new(-0.5, 0, -0.1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.125)
-- Closing Blur effect
if Blur.Size >= 1 then
repeat
Blur.Size = math.max(Blur.Size - 5, 0)
wait(0.125)
until Blur.Size == 0
end
-- Adjusting Ambience volume again
if game.SoundService.Ambience.Volume == 0.5 then
repeat
game.SoundService.Ambience.Volume = math.min(game.SoundService.Ambience.Volume + 0.5, 1)
wait(0.125)
until game.SoundService.Ambience.Volume == 1
elseif game.SoundService.Ambience.Volume == 0 then
game.SoundService.Ambience.Volume = 1
repeat
game.SoundService.Ambience.Volume = math.min(game.SoundService.Ambience.Volume + 0.5, 1)
wait(0.125)
until game.SoundService.Ambience.Volume == 1
end
end
end)
Ambience
if AmbienceMusicButton then
AmbienceMusicButton.MouseButton1Up:Connect(function()
if game.SoundService.Ambience.Volume == 0 then
game.SoundService.Ambience.Volume = 1
AmbienceMusicButton.TextColor3 = Color3.fromRGB(0, 255, 0)
else
game.SoundService.Ambience.Volume = 0
AmbienceMusicButton.TextColor3 = Color3.fromRGB(255, 0, 0)
end
game.SoundService.Ambience.Playing = (game.SoundService.Ambience.Volume > 0)
end)
else
warn("AmbienceMusicButton not found. Make sure it is defined.")
end