Hello, Im doing a volume changer system but Im stuck and I dont know how to continue it, here is one image of it
I actually have no idea how to do it so I decided to ask chatGPT how to do it, it gave me a code but it works really bad, here is it:
local UserInputService = game:GetService("UserInputService")
local music = game.ReplicatedStorage:WaitForChild("BackroundMusic",wait())
local InitialMusicVolume = music.Volume
local FULL_VOLUME_VARIABLE = InitialMusicVolume / 100
local BarDetector = script.Parent.Parent["Music Line"]
local VolumeSlider = script.Parent
local function SetVolume()
local sliderPosition = math.clamp(UserInputService:GetMouseLocation().X - VolumeSlider.AbsolutePosition.X, 0, BarDetector.AbsoluteSize.X)
local maxSliderPosition = BarDetector.AbsoluteSize.X - VolumeSlider.AbsoluteSize.X
local percentage = sliderPosition / maxSliderPosition
local newVolume = math.clamp(percentage, 0, 1) * FULL_VOLUME_VARIABLE
music.Volume = newVolume
VolumeSlider.Position = UDim2.new(sliderPosition, 0, 0, 0)
end
local function ConnectVolumeChange()
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
SetVolume()
end
end)
end
local function DisconnectVolumeChange()
VolumeSlider.MouseMoved:Disconnect()
end
VolumeSlider.MouseButton1Down:Connect(ConnectVolumeChange)
VolumeSlider.MouseButton1Up:Connect(DisconnectVolumeChange)
I would be really happy if someone can help me.
What is not working?, when i drag the textbutton, it moves but goes up like the image below, and the volume is going to 0.