How Do I Make This Work?

Hi, I’m trying to get a part to follow the player’s cursor when ever they move it however I can’t seem to get it right. Any help would be appreciated. (Script in StarterPlayerScripts btw)

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
	workspace.Part.CFrame = Mouse.Target.Position
end)

I am not very good at scripting also.

first: use a localScript or it wont work

should be Hit
https://developer.roblox.com/en-us/api-reference/class/Mouse

what is the error?

Still just gave the same error.

Try;

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
 local posX, posY, posZ = Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z

game.Workspace.Part.Position = Vector3.new(posX, posY, posZ)
end)
1 Like

This works however the part just flies towards the camera. I tried using vector 2 but that just disabled it from following the cursor.

UPDATE: I managed to fix it by setting the X axis to a stable number so now it’s only moving in the Y and Z axis.

local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()

local part = workspace:WaitForChild("Part")
mouse.TargetFilter = part

mouse.Move:Connect(function()
	part.Position = mouse.Hit.Position
end)

I believe this is what you were trying to achieve.