I think you need to change the first target.CanGrab to target:FindFirstChild(“CanGrab”)
The problem is that with the dot notation it’ll throw an error, whereas FindFirstChild will just return nil. Then the if check will fail if there’s no result.
Would end up with:
game:GetService("RunService").Heartbeat:Connect(function()
if target and target:FindFirstChild("CanGrab") and target.CanGrab.Value == script.Parent.Name then
local pos = hrp.Position + (mouse.Hit.Position - hrp.Position).Unit * 10
target.BodyPosition.Position = pos
target.CFrame = CFrame.new(Vector3.zero, mouse.Hit.LookVector) + target.Position
target.CFrame = target.CFrame*CFrame.Angles(0, math.pi, 0)
target.BodyGyro.CFrame = target.CFrame
else
end
end)