Glitch With Building Script


So The video above is the error (if the video is showing)

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local IsEquipped = false
local Mouse = plr:GetMouse()
local db = false
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local function SnapF(X,Snap)
	return math.round((X/Snap)+0.5)*Snap
end
local oldSize = nil
Char.ChildAdded:Connect(function(Child)
	if Child:IsA("Tool") and Child:FindFirstChild("IsBuldingBlock") then
		oldSize = Child.Handle.Size
		Child.Handle.Size = Child.Handle.Size - Vector3.new (Child.Handle.Size.X/2,Child.Handle.Size.Y/2,Child.Handle.Size.Z/2)
		Handle = Child.Handle
		C = Handle:Clone()
		C.Parent = game.Workspace
		IsEquipped = true
	end
end)

Char.ChildRemoved:Connect(function(Child)
	if Child:IsA("Tool") and Child:FindFirstChild("IsBuldingBlock") then
		Child.Handle.Transparency = 0
		Child.Handle.Size = oldSize
		IsEquipped = false
		C:Destroy()
	end
end)
local Orientation = 0
UIS.InputBegan:Connect(function(I)
	if I.KeyCode == Enum.KeyCode.X then
		Orientation = Orientation + 90
	end
end)
RunService.RenderStepped:Connect(function()
	if IsEquipped then
		local TargetSurface = Mouse.TargetSurface
		local X,Y,Z = Mouse.Hit.Position.X,Mouse.Hit.Position.Y,Mouse.Hit.Position.Z
		
		C.Size = oldSize
		Position = Vector3.new(SnapF(X,2),SnapF(Y,2)+C.Size.Y/2,SnapF(Z,2))
		C.Orientation = Vector3.new(0,Orientation,0)
		C.Position = Position
		C.Transparency = 0.75
		C.BrickColor = BrickColor.new("Lime green")
		C.CanCollide = false
	end
end)
Mouse.Button1Down:Connect(function()
	if not db then
		db = true
		local Part = Handle:Clone()
		Part.Position = Position
		Part.Size = C.Size
		Part.Anchored = true
		Part.Parent = game.Workspace
		Part.Transparency = 0
		Part.CanCollide = true
		Part.Name = "Wall"
		Part.Orientation = C.Orientation
		wait(0.1)
		db = false
	end
end)

This is my code and now let me tell you the error
so my code has a big that sometimes the ā€œCā€'s Y position kinda glitched idk why and how but it does for some reason the video shows it

local Target = Mouse.Target
Position = Vector3.new(SnapF(X,2),SnapF(Y,2)+Target.Size.Y,SnapF(Z,2))

it did not even helped bruh like wha

		local Distance = math.round((C.Position - game.Workspace.CurrentCamera.CFrame.Position).Magnitude)
		C.Orientation = Vector3.new(0,Orientation,0)
		C.Transparency = 1
		C.CanCollide = false
		local Target = Mouse.Target
		if Distance < 20 then
			return
		end

Fixed it

Was this with or without mouse.Target?

without mouse.target ok (IGNORE)