Moving part on a certain axis

Hello, I am making a table tennis like game where I want the racket to move on the Z axis, I made a brief prototype which has a lot of bugs with the movement on the axis, it usually just bugs when you move your mouse too fast. How would I be able to achieve a smooth version of this? Thanks.

This is my code:

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

game:GetService("RunService").RenderStepped:Connect(function()
	if mouse.Hit then
		workspace.main.PrimaryPart.Position = Vector3.new(workspace.main.PrimaryPart.Position.X, workspace.main.PrimaryPart.Position.Y, mouse.Hit.p.Z)
	end
end)

First of all, you should do

local P = workspace.main.PrimaryPart.Position
workspace.main:SetPrimaryPartCFrame(CFrame.new(P.X, P.Y, mouse.Hit.Position.Z))

Then, what is the bug you want to resolve?

Oh wait! This was the solution, thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.