Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make my move tool not go through bricks?

Asked by
Seyfert 90
6 years ago

I understand that my move tool is using CFrame which means it can easily go through bricks, I want to make it so it will not be CFramed into a brick, do I just use magnitude?

Here is my code

 local player = game.Players.LocalPlayer
 local mouse = player:GetMouse()
 local moveEvent = nil --We need to store the event so we may disconnect when left-click is released

mouse.Button1Down:connect(function()
    local target = mouse.Target
    if target and target.Parent.Name == "Furniture" then
            --target.Parent.PrimaryPart = target --Priamry Part is defined in the Model
            mouse.TargetFilter = target
                moveEvent = mouse.Move:connect(function()
                    if (player.Character.UpperTorso.Position - mouse.TargetFilter.Position).magnitude <= 35 then
                        target.Parent:SetPrimaryPartCFrame(CFrame.new((mouse.Hit.p)))    
                    else  
                        moveEvent:disconnect()
                    end                   
              end)
       end
 end)

Answer this question