Trying to make a building system

Hello all, I’ve been trying to make a building system that displays a preview of a part before placing it down, I’ve got it mostly working, but I’m getting some unexpected behavior. The issue right now is the ghost part. Sometimes it will just fly at the camera, and I’m not entirely sure why. Does anyone have any tips for me that could help? Any help is appreciated. (Video and Code Below)

local function PreviewBlock(Part)
	EquippedV = true
	local GhostPart = Instance.new("Part")
	GhostPart.Anchored = true
	GhostPart.Name = "GhostPart"
	GhostPart.Parent = game.Workspace
	GhostPart.Color = Color3.fromRGB(120, 120, 120)
	GhostPart.Transparency = 1
	GhostPart.Size = Vector3.new(5, 5, 5) -- Temporary
	GhostPart.CanCollide = false
	GhostPart.CanTouch = false
	if EquippedV == true then
		GhostPart.Transparency = 0.7
		repeat
			local Pos1 = Mouse.Hit
			LastPos = Pos1
			wait()
			local Position = Mouse.Hit
			if Position == LastPos then
				print("MNM") -- Mouse Not Moving
				task.wait()
			else
				local NewC = Mouse.Hit.p
				print("Update")
				GhostPart.Transparency = 0.7
				GhostPart.CFrame = CFrame.new(NewC.X, NewC.Y + GhostPart.Size.Y/2, NewC.Z)
			end
		task.wait(0.01)
		until EquippedV == false
		print("Destory")
		GhostPart:Destroy()
	else
		wait()
		GhostPart.Transparency = 1
	end
end

https://youtu.be/20Fv1c2tYl8

It’s because your mouse is hitting it. Use Mouse.TargetFilter = ghostpart

1 Like

You can do what @ExercitusMortem recommended, or you can set the part’s CanQuery property to false, which is more desirable than Mouse.TargetFilter since TargetFilter only accepts a single BasePart, and using CanQuery allows you to have multiple ghost parts without issue if needed.

1 Like

Thanks! Quite new to this, working well now.

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