My music volume script aint working

local Slider = script.Parent
local SliderBtn = Slider.Button
local Player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local RuS = game:GetService("RunService")

local held = false
local step = 0.1
local percentage = 0

function snap(number, factor)
	if factor == 0 then
		return number
	else
		return math.floor(number/factor+0.5)*factor
	end
end

UIS.InputEnded:connect(function(input, processed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		held = false
	end
end)

SliderBtn.MouseButton1Down:connect(function()
	held = true
end)

RuS.RenderStepped:connect(function(delta)
	if held then
		local MousePos = UIS:GetMouseLocation().X
		local BtnPos = SliderBtn.Position
		local SliderSize = Slider.AbsoluteSize.X
		local SliderPos = Slider.AbsolutePosition.X
		local pos = snap((MousePos-SliderPos)/SliderSize,step)
		percentage = math.clamp(pos,0,1)
		SliderBtn.Position = UDim2.new(percentage,0,BtnPos.Y.Scale, BtnPos.Y.Offset)
	end
end)

[Volume slider gui]
help would be appriciated. I am still learning scripting so explainations would be nice too!

I know that you need to use

Sound.Volume = 1 -- your volume  
--second version
Sound.Volume = Sound.Volume - 0.5 --It makes volume higher or lower for example on button touch  
1 Like

this is the slider script for changing volumes:

if script.Parent.Position == ({0, 0,0, 0}) then
	game.Workspace.MusicBackground.Zones.Center.Music.Chill.Volume = 0
	game.Workspace.MusicBackground.Zones.Center.Music.Chill2.Volume = 0
	game.Workspace.MusicBackground.Zones.Center.Music.Attached.Volume = 0
	game.Workspace.MusicBackground.Zones.Center.Music.Idealism.Volume = 0
	game.Workspace.MusicBackground.Zones.Center.Music.Technicolor.Volume = 0
end

if script.Parent.Position == ({0.998, 0,0, 0}) then
	game.Workspace.MusicBackground.Zones.Center.Music.Chill.Volume = 0.5
	game.Workspace.MusicBackground.Zones.Center.Music.Chill2.Volume = 0.5
	game.Workspace.MusicBackground.Zones.Center.Music.Attached.Volume = 0.5
	game.Workspace.MusicBackground.Zones.Center.Music.Idealism.Volume = 0.5
	game.Workspace.MusicBackground.Zones.Center.Music.Technicolor.Volume = 0.5
end

what i really need to know is should i make it look like volume.value or what

This is a message from @bookmarks he said yea because u dont do position like that position is a vector3 value do if position == Vector3.new(0, 0, 0) then if you need help message him on discord book#0860

1 Like