Getting a mouse position relative to a Frame for a slider?

So right now as you can see the slide isn’t very “Up to date” with the mouse and my solution would require me to somehow retrieve the mouse position relative to the frame. Right now this is what I’m doing:

local maxA = 100
local maxB = 100
local maxC = 100

local currentA = 0
local currentB = 0
local currentC = 0
local HoldingSlider = nil

-- Hair Coloring
for _, Slider in Pairs(Coloring.Hair:GetChildren()) do
	if Slider:IsA("Frame") then
		connections[Slider.Name.." Holder"] = Slider.Button.MouseButton1Down:Connect(function()
			HoldingSlider = Slider.Name:sub(7)
		 Slider.Button.MouseEnter:Connect(function(x, y)
			print("The user's mouse cursor has entered the GuiObject at position (" .. x .. ", " .. y .. ").")
		connections[Slider.Name.." UnHolder"] = Slider.Button.MouseButton1Up:Connect(function()
			HoldingSlider = nil

connections["MouseMove"] = Mouse.Move:Connect(function()
	if RightHolding then
		TweenService:Create(custoModel.PrimaryPart,, {["CFrame"] = custoModel.PrimaryPart.CFrame*CFrame.Angles(math.rad((Mouse.Y - MouseY)*-1),math.rad(Mouse.X - MouseX),0)}):Play()
		MouseX = Mouse.X
		MouseY = Mouse.Y
	elseif HoldingSlider ~= nil then
		if HoldingSlider == "A" then
			currentA = currentA + (Mouse.X - MouseX)/250
			if currentA < 0 then
				currentA = 0
			elseif currentA > maxA then
				currentA = maxA
			TweenService:Create(Coloring.Hair.SliderA.Button,, {Position =,0,0.5,0)}):Play()
		elseif HoldingSlider == "B" then
			currentB = currentB + (Mouse.X - MouseX)/250
			if currentB < 0 then
				currentB = 0
			elseif currentB > maxB then
				currentB = maxB
			TweenService:Create(Coloring.Hair.SliderB.Button,, {Position =,0,0.5,0)}):Play()
		elseif HoldingSlider == "C" then
				currentC = currentC + (Mouse.X - MouseX)/250
			if currentC < 0 then
				currentC = 0
			elseif currentC > maxC then
				currentC = maxC
			TweenService:Create(Coloring.Hair.SliderC.Button,, {Position =,0,0.5,0)}):Play()
		for _, Hair in Pairs(custoModel.Hair:GetChildren()) do
			Hair.Mesh.VertexColor =, currentB, currentC)
		Coloring.Hair.Visuals.a.Text = "VALUE: ("..math.floor(currentA)..","..math.floor(currentB)..","..math.floor(currentC)..")"
		MouseX = Mouse.X
		MouseY = Mouse.Y

Please do note some information is currently missing as I’ve only shown the most relevant parts of the script. If any other part is required please let me know.

Anyway thank you for any feedback I get.

There are already a few posts on how to do this. I recommend that you try searching the devforum before posting, so you can get answers to your questions faster and not have forum members answer duplicate questions.

Here’s a few results you could try:

If these posts don’t answer your question, these devhub articles may assist you: