Setting a Part's position the exact, the mouse cursor is pointing to in 3D Space

  1. What do you want to achieve?

Hello, I decided to script a building system for my game. The first goal was, that a part would have the exact position, the cursor is pointing to in 3D Space.

It should look like this:

My script:

--Local Script, StarterPlayerScripts
local Player = game.Players.LocalPlayer
local Part = game.Workspace.Wood
local Mouse = Player:GetMouse()
while wait() do
	Part.CFrame = Mouse.Hit
end
  1. What is the issue?

  1. What solutions have you tried so far?

I looked in the Developer Hub, but I found nothing that could fix my problem.

Any help would be appreciated

1 Like

Make sure your box is anchored.

The mouse.Hit is detecting the part and placing it ontop of that.

To fix this use

Mouse.TargetFilter = Part

just under where you defined mouse.

3 Likes

Thank you for your help, I appreciate it.