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

https://gyazo.com/9c62a44bf80829da6206b810fd2931f9

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)
		end)
		 Slider.Button.MouseEnter:Connect(function(x, y)
			print("The user's mouse cursor has entered the GuiObject at position (" .. x .. ", " .. y .. ").")
		end)
		connections[Slider.Name.." UnHolder"] = Slider.Button.MouseButton1Up:Connect(function()
			HoldingSlider = nil
		end)
	end
end


connections["MouseMove"] = Mouse.Move:Connect(function()
	if RightHolding then
		
		TweenService:Create(custoModel.PrimaryPart, TweenInfo.new(0.1), {["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
			end
			
			TweenService:Create(Coloring.Hair.SliderA.Button, TweenInfo.new(0.1), {Position = UDim2.new(currentA/maxA,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
			end
			
			TweenService:Create(Coloring.Hair.SliderB.Button, TweenInfo.new(0.1), {Position = UDim2.new(currentB/maxB,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
			end
			
			TweenService:Create(Coloring.Hair.SliderC.Button, TweenInfo.new(0.1), {Position = UDim2.new(currentC/maxC,0,0.5,0)}):Play()
		end
		
		for _, Hair in Pairs(custoModel.Hair:GetChildren()) do
			Hair.Mesh.VertexColor = Vector3.new(currentA, currentB, currentC)
		end
		
		Coloring.Hair.Visuals.a.Text = "VALUE: ("..math.floor(currentA)..","..math.floor(currentB)..","..math.floor(currentC)..")"
	else
		MouseX = Mouse.X
		MouseY = Mouse.Y
	end
end)

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:

4 Likes