Part flying torwards camera (I really need help)

I got a placement system and uh… I have a green cube that shows where a part is going to be placed. And well when I equip the tool the part tat is supposed to follow the mouse keeps flying towards my camera. The script is a local script and is inside the tool…

local tool = script.Parent

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

local mouse = player:GetMouse()

local follow = true



function onEquip()
local e = Instance.new("Part")
	e.Size = Vector3.new(2,2,2)
	e.Transparency = 0.5
	e.Color = Color3.new(0.333333, 1, 0)
	e.Parent = workspace
	e.Massless = true
	e.Anchored = true
	
	while follow do
		wait()
		e.Position = mouse.Hit.Position
	end
end


tool.Equipped:Connect(onEquip)

I think you should filtering out the placed part/model from mouse.hit object list.
If you have one object to filter it is simple enough, if you have more, you should change to raycasting instead of mouse.hit.

https://developer.roblox.com/en-us/api-reference/property/Mouse/TargetFilter

I totally forgot about target filter. I emplemented it and now it works! Thanks!. Is there anywayd for me to offset it also because the green part is in half now because some of it is in the baseplate…

e.Position = mouse.Hit.Position + e.Size.Y/2

A BasePart instances position is always the center of the BasePart, so you need to elevate its position by half its height in order for it to not clip into the ground.

Thanks! Could you explain why “size” is used and what .Y/2 means?

Btw When I unequip the tool, and then re equip it flys torwards the camera again