I found this slider off toolbox looking to make it so that wherever the slider is, the music volume changes. A slider that changes every single sound in the game’s volume. Whether its 0 to 1. I added a table so that the table can store all the sounds so that they could have their volumes changed. However, the table for some reason does not work hence the slider doesn’t succeed in changing the volume. I haven’t found any topics regarding sliders that change ALL the games sound volume, only 1 sound.
local sliderBG = script.Parent
local slider = sliderBG:WaitForChild("Slider")
local sliderBox = sliderBG:WaitForChild("SliderInput")
local speakers = game.StarterGui.Sounds -- or where the folder is
local music = {}
for _,v in pairs(speakers:GetDescendants()) do
if v:isA("Sound") then
table.insert(music,v)
end
end
local mouse = game.Players.LocalPlayer:GetMouse()
local snapAmount = 100
local pixelsFromEdge = 10
local movingSlider = false
slider.MouseButton1Down:Connect(function()
movingSlider = true
end)
slider.MouseButton1Up:Connect(function()
movingSlider = false
end)
mouse.Button1Up:Connect(function()
movingSlider = false
end)
mouse.Move:Connect(function()
if movingSlider then
local xOffset = math.floor((mouse.X - sliderBG.AbsolutePosition.X) / snapAmount + 0.5) * snapAmount
local xOffsetClamped = math.clamp(xOffset, pixelsFromEdge, sliderBG.AbsoluteSize.X - pixelsFromEdge)
local sliderPosNew = UDim2.new(0, xOffsetClamped, slider.Position.Y)
slider.Position = sliderPosNew
local roundedAbsSize = math.floor(sliderBG.AbsoluteSize.X / snapAmount + 0.5) * snapAmount
local roundedOffsetClamped = math.floor(xOffsetClamped / snapAmount + 0.5) * snapAmount
local sliderValue = roundedOffsetClamped / roundedAbsSize
music.Volume = sliderValue
end
end)
sliderBox.FocusLost:Connect(function(enterPressed)
if not enterPressed then return end
local input = tonumber(sliderBox.Text)
if input then
local inputClamped = math.clamp(input, 0, 1)
music.Volume = inputClamped
local xOffset = inputClamped * math.floor(sliderBG.AbsoluteSize.X / snapAmount + 0.5) * snapAmount
local xOffsetRounded = math.floor(xOffset / snapAmount + 0.5) * snapAmount
local xOffsetClamped = math.clamp(xOffsetRounded, pixelsFromEdge, sliderBG.AbsoluteSize.X - pixelsFromEdge)
local sliderPosNew = UDim2.new(0, xOffsetClamped, slider.Position.Y)
slider.Position = sliderPosNew
end
end)