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