GUI Slider bugs out when moved?

So recently I attempted to follow a tutorial that showed how to make a gui slider, however the tutorial moved the slider via position instead of size.

I tried to tweak it to how I am doing mine (by expanding the size) but whenever I do, it does this weird thing and bugs out.

Code:

slider.SliderButton.MouseButton1Down:Connect(function()
		Dragging = true
	end)
	
	UIS.InputChanged:Connect(function()
		if Dragging then
			local MousePos = UIS:GetMouseLocation()+Vector2.new(0,36)
			local relPos = MousePos - slider.SliderButton.AbsolutePosition
			local percent = math.clamp(relPos.X/slider.SliderButton.AbsoluteSize.X,0, 1)
			slider.SliderButton.Size = UDim2.new(percent, 0, 0, 16)
			print(percent*100)
		end
	end)
	
	UIS.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			Dragging = false
		end
	end)

SliderButton is the button I use for both pressing the slider and expanding it (let me know if i should change that)

As shown in the video, it appears that the percent is constantly going back to 100.

If anybody experienced with this could reply hopefully explaining how it works and how to fix it would be amazing.

Here you go Noah

local Slider = script.Parent.Slider
local UIS = game:GetService("UserInputService")
local Dragging = false


local function Update()
	if Dragging then
		local MousePos = UIS:GetMouseLocation()
		local MinPoint = (Slider.AbsolutePosition.X)
		local MaxPoint = (Slider.AbsolutePosition.X + Slider.AbsoluteSize.X)
		if MousePos.X < MinPoint then
			Slider.Indicator.Size = UDim2.fromScale(0, 1)
		elseif MousePos.X > MaxPoint then
			Slider.Indicator.Size = UDim2.fromScale(1, 1)
		else
			Slider.Indicator.Size = UDim2.fromScale((MousePos.X-Slider.AbsolutePosition.X)/Slider.AbsoluteSize.X, 1)
		end
	end
end


Slider.MouseButton1Down:Connect(function()
	Dragging = true
	Update()
end)


UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		Dragging = false
	end
end)


UIS.InputChanged:Connect(Update)

SliderGui.rbxl (25.8 KB)