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:
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
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.