I want a part to follow my mouse y axis

Hey guys

this is my code

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

local part = game.Workspace:FindFirstChild(“Headless Dummy”).Torso
mouse.Move:Connect(function()
part.Position = Vector3.new(part.CFrame.X, mouse.Hit.Position.Y, part.CFrame.Z)
end)

this is my code but when i run the script, the y axis of the torso isnt as the same as my mouse y axis, you can see it in the following screenshot

Ekran Alıntısı

how can i make it the same y level as my mouse cursor? can someone code and explain it for me? (its for FPS (First person) by the way.

is the script in a local player script?

1 Like

yes its a localplayer script, can you make it %100 accurate as my mouse y level?

1 Like

try putting
mouse.TargetFilter = game.Players.LocalPlayer.Character
maybe the mouse is colliding with your character and therefore wrong position

1 Like

There is a new dragdetector on roblox, you can use that

1 Like

nope that doesn’t do any help, its not colliding with anything since its just Y axis of my mouse

1 Like

its not supposed to be like that not dragging but just follows my mouse y axis

that doesn’t do any help too bro, im dead confused.

local mouse = game.Players.LocalPlayer:GetMouse()
local part = game.Workspace:FindFirstChild(“Headless Dummy”).Torso

mouse.Move:Connect(function()
part.Position = Vector3.new(part.Position.X, mouse.Hit.Position.Y, part.Position.Z)
end)

basically we keep the x and z pos as it says part.position.x and part.position.z and then we take the mouse cframe in the world space (by mouse.hit) and then we get the y axis of it

i suggested the same thing
it wont work

hmm thats strange it should work i dont see any errors or typos

try to substract the currently position of the part to the mouse hit position

Why dont you change the targetPosition like this? (with Mouse.Hit, change it for z if you want to)

local targetPosition = Vector3.new(mouse.Hit.Position.X, mouse.Hit.Position.Y, mouse.Hit.Position.Z)

i only want it to follow my mouse y axis

part.Position = Vector3.new(part.CFrame.X, part.CFrame.Y - mouse.Hit.Position.Y, part.CFrame.Z)

idk if it would work because probably the character is gonna fly XD

i will try that 1 sec ill respond you

yep it flew away … xd… brooo whys this happening im so confused

give me few minutes i know how to fix

thats because when you move the mouse youre activating the function, thats doing the Y movement once and once again, so we need the value just once, the thing is to thing how XDDD

could be more useful to print the values of the mouse hit Y pos, to know wath is happening and compare that pos with the character pos