Block Placing Tool not updating block position?

Hello, so I feel like this is a super simple solution I’m overlooking here but I have a tool that acts a lot like placing blocks in Minecraft but this tool shows you where you are placing before you click. Here’s a picture to make more sense:
image
Now my problem is it only shows that little preview when you first equip the tool and does not update afterwards. If I move my mouse around that little preview block stays right there. Here is a GIF:
https://gyazo.com/58cad6aa164f17577967c9b696dce771
Here is the full code, basically lines 25-30 are the key ones here:

local Plr = game.Players.LocalPlayer
local Rep = game.ReplicatedStorage
local Eve = Rep.Events
Tool = script.Parent
local m = Plr:GetMouse()
local Distance = 200
local ignoreList = Plr.Character, workspace.Ignore

local function onActivated()

end

local function onUnequip()
workspace.Ignore.PlaceBlock:Destroy()
end

local function onEquipped()
local pb = Rep.PlaceBlock
local pc = pb:Clone()
pc.Parent = workspace.Ignore
local target = m.Target
local face = m.TargetSurface
m.TargetFilter = ignoreList

m.Move:connect(function() --This function is what seems broken
	if target ~= nil then
		local magnitude = (Plr.Character.Head.Position - m.Target.Position).Magnitude
		if magnitude <= Distance then
			pc.CFrame = CFrame.new(target.Position + (Vector3.FromNormalId(face) * pc.Size))
		end
	else
		return
	end
end)

end


Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnequip)

Any help here would be appreciated :slight_smile:

P.S A minor side problem which I should be able to solve but if someone has seen this before and has a fix, it would make my life a lot easier. If you open the tool and the little preview block places then move your mouse into the open where there is no part you will get the error:

Players.CrispyBrix.Backpack.Place.Control:27: attempt to index field ‘Target’ (a nil value)

Which I thought I covered right after the m.Move function where I check if the Target is nil but I guess not.

Is the problem that localvar “target” only updates at the beginning of the function “onequiped”, rather than at every iteration of m.Move?

I’m not too experienced with mouse so don’t take my word for this, but you’re essentially creating a new mouse.Move function every time the tool is equipped. Try creating a connection and when it is unequipped, disconnect it. (Side problem: To fix your problem with the nil, you could try seeing if the target is a part (e.g if mouse.Target:IsA(‘BasePart’) )

If this doesn’t work, then try doing a print statement inside of the move function and seeing if it continues printing when it does that bug. Let me know the result. If it stops printing, then you know you have a problem with your code and you can find which line it is exactly by moving the print statement up/down.