Converting MouseMovement input.Position into part.Position

i am having trouble using UserInputServices’ mouseMovement to move a part on a line. it doesn’t follow where the mouse moves and the increments are way different to coordinates on the workspace

local UIS = game:GetService("UserInputService")
local part = Instance.new("Part")
local pos = Vector3.new(0,3,-35)
part.Parent = workspace
part.Position = pos
part.Anchored = true

UIS.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		
		local x = input.Position.X / 48
		part.Position = Vector3.new(x, pos.Y, pos.Z)
		print(input.Position)
		print(part.Position)
		
	end
end)

here is the code i tried, im not sure if there should be specific math i should use or another service/function

(i used 48 since that is the size of the path that i want the part to follow)

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Changed:Connect(function()
	local X = Mouse.X
end)

Try and see if Mouse.X is different from the value you have

local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
local part = Instance.new("Part")
local pos = Vector3.new(0,3,-35)
part.Parent = workspace
part.Position = pos
part.Anchored = true

Mouse.Move:Connect(function()
	local MouseScale = Mouse.X / Mouse.ViewSizeX
	local X = MouseScale * 48
	part.Position = Vector3.new(X, pos.Y, pos.Z)
	print(part.Position)
end)

This would be the complete code
Edit: Changed the event to Mouse.Move

1 Like