Sound wont decrease volume

  1. What do you want to achieve? Keep it simple and clear!
    Im trying to make an audio decrease volume when button is pressed in a for loop!
  2. What is the issue? Include screenshots / videos if possible!
    it isn’t decreasing when the button is pressed.
local s = workspace.SoundA
local p = game.Players.LocalPlayer
local off = false
s.Looped = true

local function playr()
	s:Play()
end

playr()

p.PlayerGui.StartMenu.MainMenu.TextButton1.MouseButton1Click:Connect(function()
	if off then
		for i = 1, 10 do
			s.Volume = s.Volume - 0.1
			wait(0.1)
		end
	end
end)
1 Like

Nowhere in your code is off turning true, so the code that should turn down the volume is never run.

Also, might I suggest using Tween Service to perform a smoother tween.

local TweenService = game:GetService("TweenService")

TweenService:Create(s, TweenInfo.new(1, Enum.EasingStyle.Linear), {Volume = 0}):Play()

Did not work, this is a localscript. Is that fine? I want it to be restricted to only the player so the whole game wont hear the main menu music.

local s = workspace.SoundA
local p = game.Players.LocalPlayer
local off = false
s.Looped = true
local TweenService = game:GetService("TweenService")


local function playr()
	s:Play()
end

playr()

p.PlayerGui.StartMenu.MainMenu.TextButton1.MouseButton1Click:Connect(function()
	TweenService:Create(s, TweenInfo.new(1, Enum.EasingStyle.Linear), {Volume = 0}):Play()
end)

Where is this script located? If it’s located in Workspace, LocalScripts don’t run there. Try parenting the LocalScript under your TextButton1 instance.

local TweenService = game:GetService("TweenService")
local Button = script.Parent

local s = workspace.SoundA
s.Looped = true


local function playr()
	s:Play()
end

playr()

Button.Activated:Connect(function()
	local tween = TweenService:Create(s, TweenInfo.new(1, Enum.EasingStyle.Linear), {Volume = 0})
	tween:Play()
end)

No i put it in starterplayerscripts but the script worked! Ty!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.