Help Make Slider bar

hello, I’m making a bar slider and i need help making the bar move to the mouse position when the Hitbox is clicked, i don’t have the script but i need help to make it where the X size of the bar tweens the mouse’s X Position(I think its the x Position)

i tried this, but dident work


local LowestValue = 0
local MaxValue = 10
local IsAtMax = false

local HitBox = script.Parent
local Bar = script.Parent.Parent.MainBar
local CurrentNumber = script.Parent.Parent.CurrentNumber
local CurrentNumberValue = script.Parent.Parent.CurrentNumberValue

local Mouse = game.Players.LocalPlayer:GetMouse()



HitBox.MouseButton1Click:Connect(function()
	local Pos = Mouse.X - Bar.AbsolutePosition.X
	if Pos < 0 or Pos == 0 then
		print("Is At 0")
		Pos = 0
	end
	if Pos > Bar.AbsoluteSize.X or Pos == Bar.AbsoluteSize.X then
		print("Reached The Max")
		Pos = Bar.AbsoluteSize.X
	end
	if not IsAtMax then
		print("Is Moving")
		CurrentNumberValue.Value = math.floor((Pos/Bar.AbsoluteSize.X)*MaxValue+0.5)
	else
		CurrentNumberValue.Value = (Pos/Bar.AbsoluteSize.X)*MaxValue
	end
end)